According to the documentation
If the data being deserialized is not a valid JSON document, a
JSONDecodeErrorwill be raised.
however the object response, which it of type "requests.models.Response" n'est pas serializable according to the conversion table (mentioned in doc).
A solution would be to use
geodata = response.json()
On Mon, Jan 6, 2020 at 2:20 PM Yash Garg <gargyash512@gmail.com> wrote:
--
JSONDecodeError Exception Value: Expecting value: line 1 column 1 (char 0)why i'm getting this error?views.py-ip_address = request.META.get('HTTP_X_FORWARDED_FOR', '')response = requests.get('http://freegeoip.net/json/%s' % ip_address)geodata = json.loads(response)print(geodata['ip'])print(geodata['country_name'])print(geodata['latitude'])print(geodata['longitude'])
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/34b7736d-f946-451b-b83b-de72d3329da0%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJenkLBxhDixbTDVtB_rbg%3D29QeLYQYwVtUaaHGgVWss94jQ%3DA%40mail.gmail.com.
No comments:
Post a Comment