Error

Ken R. Lewis Ken.Lewis at trinityhealth.org
Wed Jun 28 16:08:00 EDT 2017


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.Lewis at trinityhealth.org<mailto:Ken.Lewis at 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.



More information about the Python-list mailing list