Python以json方式发送数据

参考自https://blog.csdn.net/u012374229/article/details/46743877

今天在爬一个网站的时候遇到了这个问题,感谢老哥的解决方案

import urllib2
import json

data = {
    'a': 123,
    'b': 456
}
headers = {'Content-Type': 'application/json'}
request = urllib2.Request(url='url', headers=headers, data=json.dumps(data))
response = urllib2.urlopen(request)

方法就是在header里面加一句headers = {‘Content-Type’: ‘application/json’}
发送请求的时候将json数据dupms一下。

猜你喜欢

转载自blog.csdn.net/qq_40721694/article/details/82668510
今日推荐