0
我試圖使用urllib(python 3.5)進行POST調用,但無法弄清楚。有很多關於如何製作POST call without auth或call with auth, but GET的例子......我努力把2和2放在一起!有人可以幫我一個代碼嗎?如何使用auth進行urllib POST?
我試圖使用urllib(python 3.5)進行POST調用,但無法弄清楚。有很多關於如何製作POST call without auth或call with auth, but GET的例子......我努力把2和2放在一起!有人可以幫我一個代碼嗎?如何使用auth進行urllib POST?
你可以試試:
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)
https://stackoverflow.com/questions/3238925/python-urllib-urllib2-post –
'auth'在'requests'要容易得多。你可以使用 - http://docs.python-requests.org/en/master/user/authentication/。你也可以發佈你的代碼,所以我們有什麼想法你試過嗎? – droravr
感謝您的回覆,但我必須使用urllib,而不是請求。 – uzla