Skip to content

Commit 9179cc8

Browse files
authored
All setting the protocol to http (#47)
1 parent 7dbd557 commit 9179cc8

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ Load the module:
3232
from 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-
3735
Create an instance of the geocoder module, passing a valid OpenCage Data Geocoder API key
3836
as a parameter to the geocoder modules's constructor:
3937

@@ -99,6 +97,17 @@ async with OpenCageGeocode(key) as geocoder:
9997
For 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

104113
If anything goes wrong, then an exception will be raised:

opencage/geocoder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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()

test/test_all.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
geocoder = 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+
1722
def _any_result_around(results, lat=None, lon=None):
1823
for result in results:
1924
if (abs(result['geometry']['lat'] - lat) < 0.05 and

0 commit comments

Comments
 (0)