On Jun 28, 2017 1:47 PM, "Ken R. Lewis" <ken.le...@trinityhealth.org> wrote:
Hello! I am running a script, and it comes up with an error. What can I do to make the error be corrected? I am thinking it is something with the data, possibly. I have only had Python for a few days, so maybe I copied some codes wrong. Also, does Python have a way to save files downloaded from web sites? Thanks, Ken The error is on this line: data = response.json() Here is the script: #Need to install requests package for python #easy_install requests import requests # Set the request parameters url = 'https://website /file' # Eg. User name="admin", Password="admin" for this code sample. user = 'admim' pwd = 'admin' # Set proper headers #headers = {"Content-Type":"application/xml","Accept":"*/*"} # Do the HTTP request response = requests.get(url, auth=(user, pwd)) #, headers=headers ) print('Encoding:', response.encoding) print('headers:', response.headers) # Check for HTTP codes other than 200 if response.status_code != 200: print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json()) exit() # Decode the JSON response into a dictionary and use the data data = response.json() print(data) Here is the error: Encoding: UTF-8 Traceback (most recent call last): File "I:/CernerProcesses/ServiceNow/new0628.py", line 31, in <module> data = response.json() File "C:\Program Files\Python36\lib\site-packages\requests-2.18.1-py3.6.egg\requests\models.py", line 894, in json return complexjson.loads(self.text, **kwargs) File "C:\Program Files\Python36\lib\json\__init__.py", line 354, in loads return _default_decoder.decode(s) File "C:\Program Files\Python36\lib\json\decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Program Files\Python36\lib\json\decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) Ken Lewis Trinity Health I.T. Programmer Lead (701) 858-6423 Cell (701)833-8234 Fax (701) 858-6407 ken.le...@trinityhealth.org<mailto:ken.le...@trinityhealth.org> ________________________________ Confidentiality Notice: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is privileged, confidential, or otherwise exempt from disclosure under applicable law. Any unauthorized review, copy, use, disclosure or distribution is prohibited. If you have received this communication in error, please delete it from your system without copying or forwarding it and notify the sender of the error by reply e-mail. -- https://mail.python.org/mailman/listinfo/python-list Looks to me like you're not receiving any data from your request. In effect, the response body is empty. -- https://mail.python.org/mailman/listinfo/python-list