使用python调用阿里云的第三方的天气接口(urllib库的使用,url编码解码)

import urllib.request, sys
import ssl
import json
# 参考博客https://blog.csdn.net/wympqlamz15422/article/details/78778034/
# https://blog.csdn.net/wympqlamz15422/article/details/78778034/
host = 'https://jisutqybmf.market.alicloudapi.com'
path = '/weather/query'
# GET/POST 任意
method = 'GET'
appcode = '改成自己的appcode就好了'
querys = 'city=%E5%8C%97%E4%BA%AC&citycode=citycode&cityid=cityid&ip=ip&location=location'
bodys = {}
url = host + path + '?' + querys

bodys[''] = ""
post_data = bodys['']
post_data = urllib.parse.urlencode(post_data).encode("utf-8")
request = urllib.request.Request(url, post_data)
request.add_header('Authorization', 'APPCODE ' + appcode)
# 根据API的要求,定义相对应的Content-Type
request.add_header('Content-Type', 'application/json; charset=UTF-8')
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
response = urllib.request.urlopen(request, context=ctx)



content = response.read()
if (content):
    print(content)
    print(type(content))

https://www.cnblogs.com/Centwei/p/15381228.html

https://blog.csdn.net/wympqlamz15422/article/details/78778034/
实现url内容编码解码
https://www.matools.com/code-convert

https://edu.csdn.net/notebook/python/week07/10.html

https://www.runoob.com/python3/python-urllib.html

https://blog.csdn.net/u012441595/category_11375463.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值