2 Answers
0
Accepted Answer
I solved this problem.
I found that this API used Basic authentication. Username is 'account_id', password is 'license_key'. So I use 'requests.auth.HTTPBasicAuth'.
This is the code.
url1 = "https://geolite.info/geoip/v2.1/country/"
ip = os.environ['ip']
url2 ="?pretty"
url3 = url1 + ip +url2
account_id = os.environ['account_id']
license_key = os.environ['license_key']
r = requests.get(url3, auth=requests.auth.HTTPBasicAuth(account_id, license_key))
country = r.json()["country"]["names"]["ja"]
return(country)
answered 7 months ago
0
re:Post has messed up your formatting so it's a bit hard to understand, but from what I can see your "code1" is calling requests.get() like this:
requests.get(String, auth=('account_id', 'license_key'))
whereas your "code2" is calling it like this:
request.get(String)
- where "String" contains all of "'https://geolite.info/geoip/v2.1/country/3.112.189.172?pretty', auth=('account_id', 'license_key')"
So they are quite different.
Relevant content
- asked 10 months ago
- asked 4 months ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated a year ago
I'm sorry that the format is broken and it's hard to understand.
<<code1>> response = requests.get('https://geolite.info/geoip/v2.1/country/3.112.189.172?pretty', auth=('account_id', 'license_key')) return response.json()
Thanks,