Traceback (most recent call last): File "Jaipur_greater.py", line 26, in <module> data=response.json() File "/usr/lib/python3.8/site-packages/requests/models.py", line 897, in json return complexjson.loads(self.text, **kwargs) File "/usr/lib/python3.8/site-packages/simplejson/init.py", line 518, in loads return _default_decoder.decode(s) File "/usr/lib/python3.8/site-packages/simplejson/decoder.py", line 370, in decode obj, end = self.raw_decode(s) File "/usr/lib/python3.8/site-packages/simplejson/decoder.py", line 400, in raw_decode return self.scan_once(s, idx=_w(s, idx).end()) simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
This is the error when I run my code on the bash console, but it works fine on my device. Can anyone please help?? Here is my code:
import requests
import smtplib
head={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/39.0.2171.95 Safari/537.36'}
parameter={
"Accept-Language":"hi_IN",
"district_id":"505",
"date" : din
}
response=requests.get(url="https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByDistrict?"
,params=parameter,headers=head)
print(response.status_code)
data=response.json()
print(data)
length=len(data["sessions"])
msg=[]
for i in range(length):
district=data["sessions"][i]["district_name"]
name=data["sessions"][i]["name"]
address = data["sessions"][i]["address"]
age=data["sessions"][i]["min_age_limit"]
doses = data["sessions"][i]["available_capacity"]
vaccine=data["sessions"][i]["vaccine"]
if(age==18 and district=="Jaipur I"):
info=f"{doses} doses available of {vaccine} for {age}+ at {name},{address}."
msg.append(info)
message="\n".join(msg)
print(message)
with smtplib.SMTP_SSL("smtp.gmail.com") as connection:
connection.login(user=mail, password=password)
connection.sendmail(from_addr=mail,
to_addrs=recipient,
msg=message.encode("utf-8"))