>>> import requests
>>> agencies = requests.get('http://api.511.org/transit/operators?api_key=TOKENTOKENTOKENTOKENTOKEN')
>>> agencies.json()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/albertfilice/Desktop/511python3venv/lib/python3.6/site-packages/requests/models.py", line 896, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/__init__.py", line 344, in loads
s, 0)
json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)
When I look at just the text from the response, I can see it at the very start...
>>> agencies.text
'\ufeff[{"Id":"5E","Name":"511 Emergency","ShortName":"511 Emergency","SiriOperatorRef":null,"TimeZone":"America/Vancouver","DefaultLanguage":"en","ContactTelephoneNumber":null,"WebSite":null,"PrimaryMode":"other","PrivateCode":"5E","Montiored":false,"OtherModes":""},{"Id":"5F","Name":"511 Flap Sign","ShortName":"511 Flap Sign","SiriOperatorRef":null,"TimeZone":"America/Vancouver","DefaultLanguage":"en","ContactTelephoneNumber":null,"WebSite":null,"PrimaryMode":"other","PrivateCode":"5F","Montiored":false,"OtherModes":""},{"Id":"5O","Name":"511 Operations","ShortName":"511 Emergency","SiriOperatorRef":null,"TimeZone":"America/Vancouver","DefaultLanguage":"en","ContactTelephoneNumber":null,"WebSite":null,"PrimaryMode":"other","PrivateCode":"5O","Montiored":false,"OtherModes":""} ... ... ...
Is that supposed to be there? Why doesn't it just return a clean JSON response?
To get JSON response, you will need to add the format filter in your request, like
http://api.511.org/transit/operators?api_key=[your_token]&format=json
The default is XML. Hope this helps.
--Nisar
--
You received this message because you are subscribed to the Google Groups "511SFBayDeveloperResources" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
511sfbaydeveloperre...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to 511sfbaydeveloperresources+unsub...@googlegroups.com.
Please try explicitly specifying encoding to UTF-8 when saving the file. We think Python may be defaulting to a different encoding.
--Nisar
To unsubscribe from this group and stop receiving emails from it, send an email to 511sfbaydeveloperre...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "511SFBayDeveloperResources" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 511sfbaydeveloperre...@googlegroups.com.
>>> import requests
>>> agencies = requests.get('http://api.511.org/transit/operators?api_key=TOKENTOKENTOKENTOKEN&format=JSON')
>>> agencies.encoding
'utf-8'
It seems to show that the encoding is 'utf-8' already.
Are you referring to something different? Can you show me an example?
The code I posted is extremely simple, and I'm just trying to get the JSON response with the list of agencies, but I can't seem to parse the JSON.
To unsubscribe from this group and stop receiving emails from it, send an email to 511sfbaydeveloperresources+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "511SFBayDeveloperResources" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 511sfbaydeveloperresources+unsub...@googlegroups.com.
Here is what my technical team is telling me:
He needs to specify the encoding when creating the file where the JSON response is being saved. I think he has the encoding on the HTTP request.
Please ask him to provide the code and I'll give it a shot. (in case his above advice didn’t work)
--Nisar
From: 511sfbaydevel...@googlegroups.com [mailto:511sfbaydevel...@googlegroups.com]
On Behalf Of Albert Filice
Sent: Wednesday, October 10, 2018 10:52 AM
To: 511SFBayDeveloperResources <511sfbaydevel...@googlegroups.com>
Subject: Re: [511SFBayDeveloperResources] Unexpected UTF-8 BOM in JSON response
I get the list of agencies like so:
To unsubscribe from this group and stop receiving emails from it, send an email to 511sfbaydeveloperre...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "511SFBayDeveloperResources" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 511sfbaydeveloperre...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "511SFBayDeveloperResources" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 511sfbaydeveloperre...@googlegroups.com.
Thanks, Tony.
We will look into this issue and try to find a fix at our end.
--Nisar, 511 SF Bay
From: 511sfbaydevel...@googlegroups.com [mailto:511sfbaydevel...@googlegroups.com] On Behalf Of Tony Laidig
Sent: Wednesday, October 10, 2018 9:52 PM
To: 511SFBayDeveloperResources <511sfbaydevel...@googlegroups.com>
--
To unsubscribe from this group and stop receiving emails from it, send an email to 511sfbaydeveloperresources+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to 511sfbaydeveloperresources+unsub...@googlegroups.com.