请求始终返回响应 407

问题描述 投票:0回答:1

需要 407 响应方面的帮助吗?我无法解决这个问题。 我有一个韩国汽车网站的解析器,它每天工作一个月,直到显示 407 错误。我在谷歌上搜索到问题是通过代理替换解决的,但要么我做错了什么,要么代理不能解决问题。

要测试的示例代码:

import requests

proxies = {
    'https': 'http://user:[email protected]:xxxx'
}
url = 'https://api.encar.com/search/car/list/mobile?count=true&q=(And.Hidden.N._.(C.CarType.N._.Manufacturer.%EB%A7%88%EC%AF%94%EB%8B%A4.))&sr=%7CModifiedDate%7C0%7C200&inav=%7CMetadata%7CSort'
response = requests.get(url, proxies=proxies)

print(response.status_code)
python python-3.x python-requests response http-status-code-407
1个回答
0
投票

找到了解决我的问题的方法。为了不收到 407 响应,有必要从网站接收 cookie 并将它们与我的请求一起发送,这是有问题的。

为了不再出错,我使用了selenium库,它在后台启动浏览器并每5小时更新一次cookie。

附注根据经验,我得出的结论是 cookie 在 8 小时后停止工作。

© www.soinside.com 2019 - 2024. All rights reserved.