Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用auth制作urllib POST?_Python_Python 3.x_Urllib - Fatal编程技术网

Python 如何使用auth制作urllib POST?

Python 如何使用auth制作urllib POST?,python,python-3.x,urllib,Python,Python 3.x,Urllib,我试图使用(Python3.5)进行POST调用,但无法理解。有很多关于如何制作或。。。我正在努力把2和2放在一起!有人能帮我写个代码吗?你可以试试: import urllib.request auth_handler = urllib.request.HTTPBasicAuthHandler() auth_handler.add_password(realm='name', uri='url',

我试图使用(Python3.5)进行POST调用,但无法理解。有很多关于如何制作或。。。我正在努力把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)

请求中的
auth
要容易得多。你可以用那个-。另外,您是否可以发布您的代码,以便我们知道您尝试了什么?谢谢您的回复,但我必须使用urllib,而不是请求。谢谢您提供的链接,但我无法引用auth,正如我在问题中提到的那样。