我正在尝试访问网页。我尝试“UserAgent”添加标题,但是出现超时错误:我的新代码:
from fake_useragent import UserAgent
import requests
url = "https://www.bestbuy.com/site/lg-65-class-oled-b9-series-2160p-smart-4k-uhd-tv-with-hdr/6360611.p?skuId=6360611"
ua = UserAgent()
print(ua.chrome)
header = {'User-Agent':str(ua.chrome)}
print(header)
url_get = requests.get(url, headers=header)
print(url_get)
--> 285 引发 SocketError(str(e)) 286 除了 OpenSSL.SSL.ZeroReturnError 作为 e:
操作系统错误:(60,'ETIMEDOUT')
在处理上述异常的过程中,又出现了一个异常:
ProtocolError Traceback(最近一次调用最后)/anaconda3/lib/python3.6/site-packages/requests/adapters.py 在发送(自我,请求,流,超时,验证,证书,代理)439 重试=self.max_retries, --> 440 超时=超时 441 )
--> 285 引发 SocketError(str(e)) 286 除了 OpenSSL.SSL.ZeroReturnError 作为 e:
ProtocolError: ('Connection aborted.', OSError("(60, 'ETIMEDOUT')",))
在处理上述异常的过程中,又出现了一个异常: