File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,8 +32,6 @@ Load the module:
3232from opencage.geocoder import OpenCageGeocode
3333```
3434
35- ** Please note** : You will need the ability to make https requests, which is unfortunately not always the case with default installs of Python.
36-
3735Create an instance of the geocoder module, passing a valid OpenCage Data Geocoder API key
3836as a parameter to the geocoder modules's constructor:
3937
@@ -99,6 +97,17 @@ async with OpenCageGeocode(key) as geocoder:
9997For a more complete example and links to futher tutorials on asyncronous IO see
10098` batch.py ` in the ` examples ` directory.
10199
100+ ### Non-SSL API use
101+
102+ If you have trouble accesing the OpenCage API with https, e.g. issues with OpenSSL
103+ libraries in your enviroment, then you can set the 'http' protocol instead. Please
104+ understand that the connection to the OpenCage API will no longer be encrypted.
105+
106+ ``` python
107+ geocoder = OpenCageGeocode(' your-api-key' , ' http' )
108+ ```
109+
110+
102111### Exceptions
103112
104113If anything goes wrong, then an exception will be raised:
Original file line number Diff line number Diff line change @@ -125,9 +125,11 @@ class OpenCageGeocode:
125125 key = ''
126126 session = None
127127
128- def __init__ (self , key ):
128+ def __init__ (self , key , protocol = 'https' ):
129129 """Constructor."""
130130 self .key = key
131+ if protocol and protocol == 'http' :
132+ self .url = self .url .replace ('https://' , 'http://' )
131133
132134 def __enter__ (self ):
133135 self .session = requests .Session ()
Original file line number Diff line number Diff line change 1414
1515geocoder = OpenCageGeocode ('abcde' )
1616
17+ # Check if protocol can be set
18+ geocoder_http = OpenCageGeocode ('abcde' , 'http' )
19+ assert geocoder_http .url == 'http://api.opencagedata.com/geocode/v1/json'
20+
21+
1722def _any_result_around (results , lat = None , lon = None ):
1823 for result in results :
1924 if (abs (result ['geometry' ]['lat' ] - lat ) < 0.05 and
You can’t perform that action at this time.
0 commit comments