what3words / w3w-python-wrapper

Python wrapper for the what3words API
https://docs.what3words.com/api/v3/
MIT License
78 stars 14 forks source link

Reverse Geocode ConnectionError #11

Closed Koecky closed 6 years ago

Koecky commented 6 years ago

Hello @all

I get a KeyError. Here my Script:

import what3words from os import environ api_key = environ['xxxxxxxx'] w3w = what3words.Geocoder(api_key) res = w3w.reverse(lat=51.484463, lng=-0.195405) print(res)

and here the error message:

Traceback (most recent call last): File "D:/Users/name/Desktop/test.py", line 5, in api_key = environ['xxxxxxxx'] File "E:\Python27\ArcGISx6410.3\lib\os.py", line 425, in getitem return self.data[key.upper()] KeyError: 'xxxxxxxx'

and I'm confused, because there is no call on the webpage what3words.com/account/developer for the API-Key.

Sorry for my bad english ... :(

joedborg commented 6 years ago

Hey @Koecky,

I think you're trying to insert you actual key into environ. You only need to use this if you're getting the key from an environment variable.

If you just want to put your key into you script (be careful when sharing the script in this case), you just need to add the key as a string. E.g.

import what3words
api_key = 'aaabbbcccddd'

environ is used for getting environment variables from your shell. E.g.

(in Bash etc.)

export MY_KEY='aaabbbcccddd'

(in Python)

import what3words
from os import environ
api_key = environ['MY_KEY']
Koecky commented 6 years ago

Thanks @joedborg

Traceback (most recent call last): File "D:/Users/xxxxxxxxx/Desktop/test.py", line 8, in res = w3w.reverse(lat=51.484463, lng=-0.195405) File "E:\Python27\Module\w2w\what3words\what3words.py", line 92, in reverse return self._request('/reverse', params) File "E:\Python27\Module\w2w\what3words\what3words.py", line 370, in _request r = requests.get(url, params=params) File "E:\Python27\Module\requests\requests\api.py", line 72, in get return request('get', url, params=params, kwargs) File "E:\Python27\Module\requests\requests\api.py", line 58, in request return session.request(method=method, url=url, kwargs) File "E:\Python27\Module\requests\requests\sessions.py", line 508, in request resp = self.send(prep, send_kwargs) File "E:\Python27\Module\requests\requests\sessions.py", line 618, in send r = adapter.send(request, kwargs) File "E:\Python27\Module\requests\requests\adapters.py", line 508, in send raise ConnectionError(e, request=request) ConnectionError: HTTPSConnectionPool(host='api.what3words.com', port=443): Max retries exceeded with url: /v2/reverse?lang=en&coords=51.484463%2C-0.195405&display=full&key=xxxxxxxx&format=json (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000000000356F588>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed',))

Koecky commented 6 years ago

I think, I need a proxy authentication.

Koecky commented 6 years ago

like this:

httpProxy = {'username': 'xxxxxxxxxxxxxx', 'password': 'xxxxxxxxxxxx', 'host': 'HOST', 'port': 'PORT'} proxyHandler = urllib2.ProxyHandler({'http': 'http://'+httpProxy['username']+':'+httpProxy['password']+'@'+httpProxy['host']+':'+httpProxy['port']}) proxyOpener = urllib2.build_opener(proxyHandler) urllib2.install_opener(proxyOpener)

... but I don't know the host and the port from the company

joedborg commented 6 years ago

Yes, I'm afraid you'd have to get that from your IT department.

Koecky commented 6 years ago

I check it at home and if it works I will go to the IT department.

tsamaya commented 6 years ago

I am closing the issue, feel free to contact us at our support email if needed