0

i have a program and i want to show the current weather information in the corner. The code works at my own computer but at my work notebook i cant establish connection and i get this error:

requests.exceptions.ProxyError: HTTPSConnectionPool(host='api.openweathermap.org', port=443): Max retries exceeded with url: /data/2.5/weather%5Bhttps://api.openweathermap.org/data/2.5/weather%5D?APPID=abc123 d88&q=Frankfurt&units=metric (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002563074FB48>: Failed to establish a new connection: [WinError 10060]

I found this as a solution and i sounds promising: Using an HTTP Proxy

Unforutnately i dont get it how i need to implement it because i dont have knowledge about the internet settings of the company. Something similar to this:

response = requests.get(url, params=params, proxies={"http": "12.34.56.78:1234", "https": "12.34.56.78:1234"})

what i do know is that i need to set this in PyCharm's Terminal to use pip install, and it seems related:

set HTTP_PROXY=12.34.56.78:1234
set HTTPS_PROXY=12.34.56.78:1234

I dont understand much about network settings but with that it works. Would i have to do this for the program as well? The port of the error message (443) is not matching to the port i enter above (1234).

Can you help me here? Would be much apreciated! :-)

radi
  • 11
  • 4
  • you don't have to set proxy in terminal - it should work with `get( proxies={...})` but usually problem is free proxy servers are outdated and they don't work. Only paid proxy servers work correctly. Or you may try to use `Tor Network` as proxy server. – furas Jan 30 '21 at 14:44
  • in `requests` you may have to use `http://` or `https://` in addresses - `proxies={"http": "http://12.34.56.78:1234", "https": "https://12.34.56.78:1234"}` – furas Jan 30 '21 at 14:47

1 Answers1

0

I solved it:

i defined this globally:

proxies = {'http':'http://12.34.45.67:1234','https':'http://12.34.45.67:1234'}

And made my request like this:

response = requests.get(url, params=params, proxies=proxies)

I had some typos in the code before, which didnt help also ...

radi
  • 11
  • 4