I want to send a GET request to a website in on python in requests library but it is timing out. When i send a Get request in linux bash (with wget) it is responding.
This is working on python:
import requests as req
url = 'https://mkyong.com/computer-tips/how-to-view-http-headers-in-google-chrome/'
content = req.get(url, timeout=30)
print(content)
This is not working on python (I want to work with this page):
import requests as req
url = 'https://sahibinden.com/'
content = req.get(url, timeout=30)
print(content)
This is working on wget:
[input]
emr@DESKTOP-05BO8UL:~$ wget sahibinden.com
[output]
--2021-09-30 22:09:20-- http://sahibinden.com/
Resolving sahibinden.com (sahibinden.com)... 85.111.30.111
Connecting to sahibinden.com (sahibinden.com)|85.111.30.111|:80... connected.
HTTP request sent, awaiting response... 301 MOVED PERMANENTLY
Location: https://sahibinden.com/ [following]
--2021-09-30 22:09:20-- https://sahibinden.com/
Connecting to sahibinden.com (sahibinden.com)|85.111.30.111|:443... connected.
HTTP request sent, awaiting response... 301 MOVED PERMANENTLY
Location: https://www.sahibinden.com/ [following]
--2021-09-30 22:09:20-- https://www.sahibinden.com/
Resolving www.sahibinden.com (www.sahibinden.com)... 85.153.138.111
Connecting to www.sahibinden.com (www.sahibinden.com)|85.153.138.111|:443... connected.
HTTP request sent, awaiting response... 200
Length: unspecified [text/html]
Saving to: ‘index.html’
index.html [ <=> ] 200.88K --.-KB/s in 0.1s
2021-09-30 22:09:21 (1.31 MB/s) - ‘index.html’ saved [205699]
CodePudding user response:
You might need to give a user agent.
import requests as req
url = 'https://sahibinden.com/'
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
content = req.get(url, headers=headers, timeout=6)
print(content)
That specific server seems overloaded with requests, so may not be able to return anything meaningful.