我尝试使用urllib(python 3.5)进行POST调用,但无法弄清楚。有很多关于如何制作POST call without auth或call with auth, but GET的例子......我很难将2和2放在一起!有人可以帮我一个代码吗?
答案 0 :(得分:3)
您可以尝试:
import urllib.request
auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password(realm='name',
uri='url',
user='user',
passwd='pass')
opener = urllib.request.build_opener(auth_handler)
urllib.request.install_opener(opener)
req = urllib.request.Request(url=some_url, data=data, method='POST')
urllib.request.urlopen(req)