0

i´m pretty new in Python programming. I have python3 and i installed requests via pip.

I cant connect to any site with .get...

Is it a firewall or some connection problems ? I´m clueless

my code:

import requests

response = requests.get('https://google.com', timeout=20)

print(response.status_code)

Output: I get a wall of Errors, see images.

If i try to catch exeptions: Code:

import requests

try:
    response = requests.get('https://google.com', timeout=20)
    if response.status_code == 200:
        print(response.json())
    else:
        print(f"Fehler beim Abrufen der Daten. Statuscode: {response.status_code}")
except Exception as e:
    print(f"Fehler: {e}")

Output: Fehler: HTTPSConnectionPool(host='google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000215B98DE900>: Failed to establish a new connection: [WinError 10051] A socket operation was related to an unavailable network'))

1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented May 15, 2024 at 5:20

1 Answer 1

0

I don't know for sure what the issue is, however, assuming google.com is not down, most likely the reason is a firewall.

Here is how I would go about it:

  1. Try to access the same url using a browser from the same machine. If it does not work, you know it is a firewall. If it does work, I would check your browser's proxy settings.
  2. If the browser has proxy settings (whether manual or automatic), I would pass the same proxy (or proxies) to your request (e.g., requests.get(url, proxies={'http': <your_http_proxy>, 'https': <your_https_proxy>}) )

Of course for google.com to be down is not impossible, but very very unlikely

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, the main problem was the proxy connection. The codeline which ist working for my specific issue is: response = requests.get(api_endpoint, proxies={'http': user_proxy_url, 'https': user_proxy_url}, auth=(username, userpassword),timeout=10)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.