I'm trying to fetch data from Entsoe's transparency web-API on my server which is behind a proxy. However, when I run the following code I keep getting a bad handshake error. The web-API does connect from the browser.
import requests
url='https://transparency.entsoe.eu/api'
proxies = {'http':'172.26.28.25:8080', 'https':'172.26.28.25:8080'}
requests.get(url, proxies = proxies)
I keep getting error:
requests.exceptions.SSLError: HTTPSConnectionPool(host='transparency.entsoe.eu', port=443): Max retries exceeded with url: /api?... (Caused by SSLError(SSLError("bad handshake: SysCallError(10054, 'WSAECONNRESET')",),))
How can I solve this error?
Kind regards,
Matthijs Toorenburg
If you want to initiate an API call you should supply the request parameters too.
W/o an API token Rejected TP request you'd only get Unauthorized (HTTP: 401).
You should also keep in mind, that the TP allows only a limited number of requests posted from a single IP within a specific timeframe. Id. TP query limits
In other cases, you address the host of the API, without acutally initiating an API call
(you could use API Tester as a toy example).
Related
I am using the response module of python to download quite some data but I am facing an issue. Before posting my specific case, I have tried with a simpler code to test the issue and I face the same problem. Basically, when running this:
import request
x = requests.get('https://w3schools.com')
print(x.status_code)
following is the error I am facing.
ConnectionError: HTTPSConnectionPool(host='w3schools.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002240C195760>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))
Could anyone guide me on this. I suspect its an issue with my network configuration? I have no experience with network management so I am lost on that.
Thanks
Well, I just found out it is indeed an error with my network, basically missing the proxy info as I am working behind one.
For those looking at this in the future, add your proxy settings manually:
import requests
proxies = {'http': 'http://your.proxy.com:8080',
'https': 'http://your.proxy.com:8080'}
url = 'https://w3schools.com'
response = requests.post(url, proxies=proxies)
print(response.status_code)
If you get 200 then it is working.
I'm creating script which will tell us is website is down or up. But I got error HTTPSConnectionPool(host='gooogle.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError("hostname 'gooogle.com' doesn't match 'www.google.com'")))
here is my code:
import requests
website_url = input("Enter a website url: ")
r = requests.get(f'https://{website_url}', timeout=5)
if r.status_code != 200:
print(f"uh no, {website_url} is down")
else:
print(f"Good News, {website_url} is up")
I am using the requests module for this. To be honest, I don't know how to check the website is down or up but still, I write this code if you know how please answer me with details.
First of all, you're referring to https://www.gooogle.com instead of https://www.google.com; which I assume is the webpage that you want to test.
Regarding the reason of your error:
Since you're accessing with the HTTPS protocol, you will check the certificates of the destination server, in order to verify that this one is who is supposed to be.
Apparently, the domain https://www.gooogle.com is offering the same certificate than https://www.google.com, and also it performs a redirect to it, but that domain isn't included in the Subject Alternate Name (SAN) of the Google certificate, so actually you cannot verify the authenticity of the accessed domain.
If you use your code against a site that has correctly set the SSL verification, it should work without problems. On another hand, if you just want to check if a site is UP or DOWN independently on its SSL configuration, you can just pass the flag verify set to False:
requests.get(f'https://{website_url}', verify=False, timeout=5)
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! :-)
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 ...
I tried
import requests
url='https://www.cnn.com/'
r=requests.get(url)
Error:
ProxyError: HTTPConnectionPool(host=... port=80): Max retries exceeded with...
The following
print requests.utils.get_environ_proxies('http://www.google.com')
output:
http://proxy.server:3128
What can I do?
Thanks.
Jerry
www.cnn.com is not on the whitelist of sites that free accounts can access. To be included in that whitelist, a site needs to have a publicly documented API.
I am performing a REST post request using python code. I am trying to communicate with an external server. I am performing several REST calls but a specific one fails. That specific request is the following:
r = requests.post(url, json=item[1], headers=headers)
I am getting the following error:
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='....euapi', port= ...):
Max retries exceeded with url: ...(Caused by NewConnectionError
('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at: ...
Failed to establish a new connection: [Errno 11004] getaddrinfo failed',))
It seems that the server is blocking the connection to me because of the number of connction with it. However, I just perform only one call. Does that make sense? Any idea of how can I overcome this issue?
It seems that your 'url' value is not correct (address cannot be resolved). Please check it carefully
Similar question here