Ola*_*laf 5 python urlopen python-requests
我遇到了请求包的奇怪行为……或因此,我相信:
(1)对于某个网站,requests.get在Windows上运行,但在Linux上冻结(如果将超时设置为几秒钟,则会引发超时错误)
(2)urllib.request.urlopen在Windows和Linux上均可使用
是否有人建议如何进一步调试/调查?
详细信息如下:
在Windows计算机上,我在Jupyter Notebook中运行:
import sys
import requests
print(sys.version)
print(requests.__version__)
Run Code Online (Sandbox Code Playgroud)
3.6.3 | Anaconda自定义(32位)| (默认值,2017年10月15日,07:29:16)[MSC v.1900 32位(Intel)]
2.18.4
然后我尝试:
time1 = time.time()
response=requests.get('https://www.tagheuer.com/en/watches/tag-heuer-carrera-calibre-5-automatic-watch-39-mm-war211a-ba0782')
time2 = time.time()
print(response.status_code)
print(time2-time1)
Run Code Online (Sandbox Code Playgroud)
结果:
200
0.6808576583862305
到目前为止,一切顺利……然后我移至Unix服务器:
import sys
import requests
print(sys.version)
print(requests.__version__)
Run Code Online (Sandbox Code Playgroud)
3.5.2(默认值,2017年11月23日,16:37:01)\ n [GCC 5.4.0 20160609]
2.18.4
当我发出请求声明时,
response=requests.get('https://www.tagheuer.com/en/watches/tag-heuer-carrera-calibre-5-automatic-watch-39-mm-war211a-ba0782')
Run Code Online (Sandbox Code Playgroud)
回来需要很长时间。有时返回的字节看起来根本不像请求的页面。有时我会忍耐不住,按CTRL-C。
但是在同一台服务器上:
from urllib.request import urlopen
import time
url='https://www.tagheuer.com/en/watches/tag-heuer-carrera-calibre-5-automatic-watch-39-mm-war211a-ba0782'
time1 = time.time()
f = urlopen(url)
myfile = f.read()
time2 = time.time()
print(f.status)
print(time2-time1)
Run Code Online (Sandbox Code Playgroud)
完成结果
200
0.22718000411987305
为什么请求库会让我失望的是Linux机器而不是Windows机器?
为什么urllib.request.urlopen可以工作,但请求会冻结?他们在做什么不同?
两种平台上的www.google.com都可以使用相同的代码。TAG_Heuer网站的哪种(非标准?)行为会导致请求失败?
期待您的反馈和想法!
| 归档时间: |
|
| 查看次数: |
390 次 |
| 最近记录: |