'session by python to get data has a delay every few requests
I use session by python to get data from some url,but after every few visits, there is a long delay.
My code is
import time
import requests
def main():
session = requests.Session()
start = time.time()
for _ in range(100):
_start = time.time()
with session.get('https://www.mexc.ch/open/api/v2/market/depth', headers={
"Cache-Control": "no-cache",
"Pragma": "no-cache"
}, params={
"symbol": "BTC_USDT",
"depth": "2"
}) as res:
print(time.time() - _start)
end = time.time()
print(f'time is:{end - start}')
if __name__ == '__main__':
main()
and prints is
...
0.2015080451965332
0.20151209831237793
0.2026970386505127
1.340785026550293
0.2060239315032959
0.21337509155273438
0.2042250633239746
...
Output has a delay of more than 1 second.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
