Nov-08-2017, 04:48 AM
I'm trying to attach a screenshot to my post and can't a way to do this. Is this possible?
Thanks
Thanks
Not sure how to debug this?
|
Nov-08-2017, 04:48 AM
I'm trying to attach a screenshot to my post and can't a way to do this. Is this possible?
Thanks
Nov-08-2017, 05:19 AM
We don't need screenshots. Copy/paste your code in code tags and the full traceback in error tags. See BBcode for more info.
This code below throws exceptions.
import urllib.parse import requests import json main_api = 'http://maps.googleis.com/maps/api/geocode/json?' address = 'lhr' url = main_api + urllib.parse.urlencode({'address': address}) json_data = requests.get(url).json() print(json_data) HERE ARE THE EXCEPTOINS ===================================================================================== C:\Python34\python.exe "C:/Development/Python Apps/TestApp/MyPythonApp/JSONApp.py" Traceback (most recent call last): File "C:/Development/Python Apps/TestApp/MyPythonApp/JSONApp.py", line 9, in <module> json_data = requests.get(url).json() File "C:\Python34\lib\site-packages\requests\models.py", line 892, in json return complexjson.loads(self.text, **kwargs) File "C:\Python34\lib\site-packages\simplejson\__init__.py", line 517, in loads return _default_decoder.decode(s) File "C:\Python34\lib\site-packages\simplejson\decoder.py", line 370, in decode obj, end = self.raw_decode(s) File "C:\Python34\lib\site-packages\simplejson\decoder.py", line 400, in raw_decode return self.scan_once(s, idx=_w(s, idx).end()) File "C:\Python34\lib\site-packages\simplejson\scanner.py", line 79, in scan_once return _scan_once(string, idx) File "C:\Python34\lib\site-packages\simplejson\scanner.py", line 70, in _scan_once raise JSONDecodeError(errmsg, string, idx) simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0) Process finished with exit code 1
You know that the url address is wrong
googleis ?API doc. For this use Requests. Here a demo,i use string formatting to make changes in url address. import requests address = '1600 Amphitheatre Parkway Mountain View' api_key = 'Your API key' url = 'https://maps.googleapis.com/maps/api/geocode/json?address={}{}'.format(''.join(address.split()), api_key) url_get = requests.get(url) loc = url_get.json()What you get back is a Python dictionary also contain list when come from JSON. Test run. >>> loc['results'][0]['geometry'] {'bounds': {'northeast': {'lat': 37.42198310000001, 'lng': -122.0853195}, 'southwest': {'lat': 37.4214139, 'lng': -122.0860042}}, 'location': {'lat': 37.4216548, 'lng': -122.0856374}, 'location_type': 'ROOFTOP', 'viewport': {'northeast': {'lat': 37.4230474802915, 'lng': -122.0843128697085}, 'southwest': {'lat': 37.4203495197085, 'lng': -122.0870108302915}}} >>> loc['results'][0]['geometry']['location'] {'lat': 37.4216548, 'lng': -122.0856374} >>> loc['results'][0]['geometry']['location']['lat'] 37.4216548 |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
no debug messages going into log file | robertkwild | 0 | 527 |
Jul-09-2024, 05:30 PM Last Post: robertkwild |
|
pycharm debug help | mg24 | 1 | 1,689 |
Nov-18-2022, 05:38 AM Last Post: deanhystad |
|
Python debug suddenly got bad | ben1122 | 3 | 1,790 |
Sep-03-2022, 06:20 AM Last Post: ben1122 |
|
![]() |
Help Debug please | jamesaarr | 12 | 5,841 |
Jul-28-2021, 11:20 PM Last Post: Pedroski55 |
Error in Int object is not subscript-able. How to debug this ? | yanDvator | 1 | 2,771 |
Aug-03-2020, 02:28 PM Last Post: Larz60+ |
|
is there a debug mode available while creating python egg | BhushanPathak | 1 | 3,044 |
Dec-19-2018, 04:15 PM Last Post: Larz60+ |
|
Help debug my fibonacci implementation | dineshpabbi10 | 6 | 5,132 |
May-16-2018, 12:12 PM Last Post: dineshpabbi10 |
|
Debug and trace in python | quocchi22101262 | 0 | 3,886 |
Jun-20-2017, 09:35 AM Last Post: quocchi22101262 |