Like the title said, im trying to send request a url using requests with headers, but when I try to print the status code it doesn't print anything in the terminal. Here's my code ;
import requests
from bs4 import BeautifulSoup
from requests.exceptions import ReadTimeout
link="https://www.sahibinden.com"
header={
"accept-language": "tr,en;q=0.9,en-GB;q=0.8,en-US;q=0.7",
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.36'
}
r=requests.get(link)
print(r.status_code)
In terminal, nothing appears.
CodePudding user response:
you can use request.head(link) like below:
r=requests.head(link)
print(r.status_code)
CodePudding user response:
I get the same problem. The get()
never returns.
Since you have created a header
variable I thought about using that:
r = requests.get(link, headers=header)
Now I get status 200
returned.