【发布时间】:2019-05-15 02:38:53
【问题描述】:
如果我使用 Django,我无法使用 urllib2 发出请求,但是,单独运行脚本可以。
如果我在与 Django 相同的虚拟环境中单独运行脚本,它可以工作。
我正在使用的代码:
data = urllib.urlencode({'somedata':somedata})
url = "https://www.example.com"
request = urllib2.Request(url,data)
response = urllib2.urlopen(request).read()
print response
Django尝试运行时出现问题,我尝试切换网络和操作系统:
在 Ubuntu 中,我收到此错误:
<urlopen error [Errno 113] No route to host>
在 Windows 中:
<urlopen error [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>
知道为什么会这样吗?
【问题讨论】:
标签: python django python-2.7 urllib2