Python trying to send request with requests library but nothing happened?

Question:

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, I checked my internet connection and changed to test it but nothing changes.
Here’s my code ;

    import requests
    from bs4 import BeautifulSoup
    from requests.exceptions import ReadTimeout
    link="https://www.exampleurl.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)

When I execute this command, nothing appears, don’t know why. If someone can help me I will be so glad.

Asked By: Kerem

||

Answers:

you can use request.head(link) like below:

r=requests.head(link)
print(r.status_code)
Answered By: Aysan Eshraghi

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.

Answered By: quamrana