I need to get a connection to this uri: uri = 'https://www.wfs.nrw.de/geobasis/wfs_nw_inspire-flurstuecke_alkis?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&STOREDQUERY_ID=urn:ogc:def:query:OGC-WFS::GetFeatureById&ID=CadastralParcel_05518904700963______'
Because it dosen't work, i tryed this to find my misstakes:
import requests
import urllib.request
uri = 'http://www.google.de'
uriS = 'https://www.google.de'
myproxies = urllib.request.getproxies()
try:
r = requests.get(uri)
print('HTTP OK')
except:
print('HTTP NOT OK')
try:
r = requests.get(uri, proxies = myproxies)
print('HTTP WITH PROXIES OK')
except:
print('HTTP WITH PROXIES NOT OK')
try:
r = requests.get(uriS)
print('HTTPS OK')
except:
print('HTTPS NOT OK')
try:
r = requests.get(uriS, proxies = myproxies)
print('HTTPS WITH PROXIES OK')
except:
print('HTTPS WITH PROXIES NOT OK')
This is the result:
HTTP OK
HTTP WITH PROXIES OK
HTTPS NOT OK
HTTPS WITH PROXIES NOT OK
This happens when i do it in the console:
>>> import requests
>>> uri = 'https://www.google.de'
>>> r = requests.get(uri)
Traceback (most recent call last):
File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\site-packages\urllib3\connectionpool.py", line 594, in urlopen
self._prepare_proxy(conn)
File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\site-packages\urllib3\connectionpool.py", line 815, in _prepare_proxy
conn.connect()
File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\site-packages\urllib3\connection.py", line 324, in connect
self._tunnel()
File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\http\client.py", line 911, in _tunnel
message.strip()))
OSError: Tunnel connection failed: 407 Proxy Authorization Required
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\site-packages\requests\adapters.py", line 445, in send
timeout=timeout
File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\site-packages\urllib3\util\retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.google.de', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authorization Required')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "<string>", line 3, in <module>
File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\site-packages\requests\sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\site-packages\requests\sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "C:\PROGRA~1\QGIS3~1.8\apps\Python37\lib\site-packages\requests\adapters.py", line 507, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.google.de', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authorization Required')))
-
You should print out some details from the exceptions.Dave Costa– Dave Costa2020年04月02日 13:21:17 +00:00Commented Apr 2, 2020 at 13:21
-
It's hard to answer like that. It could be different reasons. You shouldn't catch the error to see what the stack trace is. My intuition would be that you have a problem with you OpenSSL installation.Alexandre Senges– Alexandre Senges2020年04月02日 13:23:02 +00:00Commented Apr 2, 2020 at 13:23
-
Does this answer your question? Python requests API using proxy for https request get 407 Proxy Authentication RequiredCraicerjack– Craicerjack2020年04月02日 13:54:08 +00:00Commented Apr 2, 2020 at 13:54
-
The information was intressting, but we solved the Problem in an other way.Wulf– Wulf2020年04月03日 08:19:39 +00:00Commented Apr 3, 2020 at 8:19
1 Answer 1
We solved the Problem!
The code was correct.
We (oure network admin) have put the uri "https://www.wfs.nrw.de" on a list for uri with no authentication needed.
import requests
import urllib.request
myproxies = urllib.request.getproxies()
uri = 'https://www.wfs.nrw.de/geobasis/wfs_nw_inspire-flurstuecke_alkis?SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&STOREDQUERY_ID=urn:ogc:def:query:OGC-WFS::GetFeatureById&ID=CadastralParcel_05518904700963______'
r = requests.get(uri, proxies = myproxies)
print(r.text)
Sign up to request clarification or add additional context in comments.
Comments
lang-py