F
F
freQuensy232020-06-19 10:52:18
Python
freQuensy23, 2020-06-19 10:52:18

Issues with requests python. How to fix an infinite request?

I'm trying to access the site `msudrf.ru` using Python requests. I write this code

import requests as req
print(1)
r = req.get("http://msudrf.ru")
print(2)

The program outputs 1 and hangs on the request, i.e. it does not reach the output of 2.
I tried to add headers, used a proxy, ran the script through Google Collabs and everywhere the same problem, requests to the site take forever. Can you suggest how to fix this problem without resorting to Selenium or similar?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Miit, 2020-06-19
@freQuensy23

Use timeout to limit request time. But in your case, apparently there is not enough User-Agent header, everything works with it.

import requests as r
res = r.get('http://msudrf.ru', timeout=10, headers={'User-Agent': 'some cool user-agent'})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question