我尝试使用 urllib 进行 POST 调用(python 3.5),但无法弄清楚。有很多关于如何制作 POST call without auth 的示例。或call with auth, but GET ...我正在努力将 2 和 2 放在一起!有人可以帮我提供代码吗?
最佳答案
你可以尝试:
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)
关于python - 如何使用 auth 进行 urllib POST?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45676263/