[英]Python3 urllib POST with HTTPS
我刚刚开始在python 3.3.3中使用urllib,并且可以使用urllib.request.urlopen()
发出POST请求。 但是,我想做的是使用HTTPS的POST。 我看到urlopen
的文档说:“当前HTTP请求是唯一使用数据的请求”(并且POST请求需要'data'参数)。
然后我看到urllib.request.HTTPSHandler
似乎能够通过其https_open()
进行HTTPS POST。 不幸的是,似乎我不知道如何使用此功能。 现在,我只想使用此处理程序执行简单的HTTPS GET,所以我尝试做的是
import urllib.request
r = urllib.request.Request("https://www.google.com")
handler = urllib.request.HTTPSHandler()
handler.https_open(r)
但这导致AttributeError: 'Request' object has no attribute 'timeout'
我如何才能使HTTPSHandler.https_open()
工作? 还是urlopen
调用https_open
函数(如果我使用过的话)
opener = urllib.request.build_opener(urllib.request.HTTPSHandler)
urllib.request.install_opener(opener)
之前,实际上是否已经发出了HTTPS POST请求? 谢谢!
尝试对urlopen
使用data=None
。
或使用请求
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.