Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请求 很容易超时 #106

Open
Su1008 opened this issue Aug 20, 2023 · 28 comments
Open

请求 很容易超时 #106

Su1008 opened this issue Aug 20, 2023 · 28 comments
Labels
bug Something isn't working

Comments

@Su1008
Copy link

Su1008 commented Aug 20, 2023

您好,我发现当轮询请求的话 很容易出现超时,已设置 类似3、5、10s超时。相比requests 同种请求出现此类问题的的频率有点高。
image

@yifeikong
Copy link
Owner

能给一下网站吗? 以及有没有用代理?

@Su1008
Copy link
Author

Su1008 commented Aug 21, 2023

没用代理 很多网站 都会如此 比如 https://union-click.jd.com/jdc?e=&p=JF8
image

@yifeikong
Copy link
Owner

代码能否贴一下,最好信息给全点,我能复现问题才能修啊

@520Error
Copy link

确实如此,尤其用了代理经常会超时,代理是没问题的

@520Error
Copy link

由于频繁访问同一个接口使用了session , 例如 s = Session() while1: s.post(xxx, proxies) 出现超时概率很大,超时后后面又会正常一会儿又会超时

@520Error
Copy link

我猜测 请求过程中丢失了某些数据导致 服务器未响应

@yifeikong
Copy link
Owner

听着像是一种频控措施啊。我还是需要能复现问题的代码才能解决这个问题。

@chinaywx
Copy link

我使用快代理里面的代理进行爬虫,很容易出现请求超时,使用国外代理会比较稳定

@zhoushun33
Copy link

请问这个问题有解决方案么,使用异步达到一定量后就会一直超时,换几轮IP都没用,尝试清除cookie也没用,只有重启程序这个情况才会好,比较奇怪

@yifeikong
Copy link
Owner

希望能有一些定量的描述,一定量是多少呢?我得能在我这边复现了才好修啊……

请问这个问题有解决方案么,使用异步达到一定量后就会一直超时,换几轮IP都没用,尝试清除cookie也没用,只有重启程序这个情况才会好,比较奇怪

@Jie-Ge
Copy link

Jie-Ge commented Nov 7, 2023

可以看看这个网站 https://www.bitget.com/zh-CN/spot/BTCUSDT 的这个接口 https://www.bitget.com/v1/kline/getMoreKlineData容易出现超时。代码如下:

from curl_cffi import requests
headers = {
    'authority': 'www.bitget.com',
    'accept': 'application/json, text/plain, */*',
    'accept-language': 'zh-CN,zh;q=0.9',
    'cache-control': 'no-cache',
    'content-type': 'application/json;charset=UTF-8',
    'cookie': 'BITGET_LOCAL_COOKIE={%22bitget_lang%22:%22zh-CN%22%2C%22bitget_unit%22:%22USD%22%2C%22bitget_showasset%22:true%2C%22bitget_theme%22:%22black%22%2C%22bitget_layout%22:%22right%22%2C%22bitget_valuationunit%22:1%2C%22bitgt_login%22:false}; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22w-283231886-1699258516804-689554544%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMThiYTNiMzQ1NWQyYmUtMDE2Yjc0ZjAzMjkxNjItMjYwMzExNTEtMjc2NDgwMC0xOGJhM2IzNDU1ZTEwZWEifQ%3D%3D%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%2C%22%24device_id%22%3A%2218ba3b3455d2be-016b74f0329162-26031151-2764800-18ba3b3455e10ea%22%7D; bt_sessonid=; bt_newsessionid=; _dx_kvani5r=7505fae63714619014184a1c4261d223aad2e32c7b3ad753213f9ace4085d17db3a11884; dy_token=6548a12da1ojEP8Y3OU1HLoLUiQZHmhHGvQl8en1; bt_rtoken=; __cf_bm=W_MX3.X.4Ar9yZVkd1KaFDlaKgc7E18jRww8l2vyblw-1699321889-0-AfrYvvYuUc+drj30muKxVU+Xaktxg3pSQutDC9abbXjCk9Lo/1oSDKVA15cm1vzj4hgdkm/+upbTMMJ1qbUiSqk=; _cfuvid=yWf767Me7NpfvL0jYlshxXqj6777OE_jvOETz8YItJg-1699321889603-0-604800000',
    'language': 'zh_CN',
    'locale': 'zh_CN',
    'origin': 'https://www.bitget.com',
    'pragma': 'no-cache',
    'referer': 'https://www.bitget.com/zh-CN/spot/BTCUSDT',
    'sec-ch-ua': '"Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'terminaltype': '1',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
    'website': 'mix',
}

data = '{"symbolId":"BTCUSDT_SPBL","kLineStep":"1Dutc","kLineType":1,"limit":100,"endTime":"1699263071079","languageType":1}'

response = requests.post('https://www.bitget.com/v1/kline/getMoreKlineData', headers=headers, data=data,
                         impersonate='chrome101', timeout=5)

@yifeikong yifeikong added the bug Something isn't working label Nov 25, 2023
@wwang129
Copy link

wwang129 commented Dec 9, 2023

我在使用中也有这个问题,完全一样的代码和代理,只是把httpx.AsyncClient()改为curl_cffi.requests.AsyncSession()就会经常超时,虽然做了重试机制之后没什么影响。

@yifeikong
Copy link
Owner

@wwang129 你使用的是什么版本?

@yifeikong
Copy link
Owner

有可能是 #164 提到的计时器泄漏的问题

@tmxd09887
Copy link

如果加了timeout=5,就大量超时
如果不加timeout,异步执行一会就卡死,大量报错Failed to perform, ErrCode: 56, Reason: 'BoringSSL SSL_read: Connection was aborted, errno 10053'. This may be a libcurl error, See https://curl.se/libcurl/c/libcurl-errors.html first for more details.

异步模式,是不是有bug?谢谢

@yifeikong
Copy link
Owner

@tmxd09887 你是升级到最新版了?0.6.0b7

@tmxd09887
Copy link

0.5.10版

@yifeikong
Copy link
Owner

可不可以试下,0.6.0b7,然后不要切换到 selector loop

@tmxd09887
Copy link

selector loop是什么意思?

@yifeikong
Copy link
Owner

这个:

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

@tmxd09887
Copy link

没区别,一样报错

@yifeikong
Copy link
Owner

你是说 0.6.0b7 去了 selector loop?哥你字打的越多,咱问题解决越快,别等我一句一句问啊……

@tmxd09887
Copy link

感谢

目前
1、更新到0.6.0b7
2、注释掉asyncio.set_event_loop_policy
3、timeout=5
大量报超时
Failed to perform, ErrCode: 28, Reason: 'Operation timed out after 5000 milliseconds with 35178 bytes received'. This may be a libcurl error, See https://curl.se/libcurl/c/libcurl-errors.html first for more details

表现跟从0.5.10版更新之前一样

@yifeikong
Copy link
Owner

核心代码贴一下吧,不方便的话可以私聊发我。

@gg336699
Copy link

gg336699 commented Jan 2, 2024

proxies = { "http": f"http://xxx-region-gb-sessid-{idd}-sessiontime-15-keep-true:xxx@xxx:4600", "https": f"http://xxx-region-gb-sessid-{idd}-sessiontime-15-keep-true:xxx@xxx:4600"} res_type = self.ses.get(self.base_url+'/Global/bls/visatypeverification',proxies=proxies,impersonate='chrome110',timeout=30)
这是我的代码,用到了代理,他偶尔会出现 errorCode 28/5x,5x具体的忘记了,但是有关SSL

@yifeikong
Copy link
Owner

@gg336699 你也是 Windows?这个楼里都是么?

@solo-xwz
Copy link

我在linux里面也会经常出现超时和报ssl错误(使用了代理),并且某些国内的直连ip代理无法使用,但是使用golang正常

@yifeikong
Copy link
Owner

@solo-xwz 请问直连代理指的是什么类型的代理?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants