Hi! I am trying to work with some API return data. My code is working on the local instance of Streamlit but when I deploy the code to Streamlit sharing, I am unable to get data from the API (returns Error 403). Same code works on local instance of Streamlit. Please help.
Code is as below
import streamlit as st
import pandas as pd
import requests
import json
from datetime import date,datetime
import geopandas as gpd
import plotly.express as px
state_index = {'Andaman and Nicobar Islands': 1,
'Andhra Pradesh': 2,
'Arunachal Pradesh': 3,
'Assam': 4,
'Bihar': 5,
'Chandigarh': 6,
'Chhattisgarh': 7,
'Dadra and Nagar Haveli': 8,
'Daman and Diu': 37,
'Delhi': 9,
'Goa': 10,
'Gujarat': 11,
'Haryana': 12,
'Himachal Pradesh': 13,
'Jammu and Kashmir': 14,
'Jharkhand': 15,
'Karnataka': 16,
'Kerala': 17,
'Ladakh': 18,
'Lakshadweep': 19,
'Madhya Pradesh': 20,
'Maharashtra': 21,
'Manipur': 22,
'Meghalaya': 23,
'Mizoram': 24,
'Nagaland': 25,
'Odisha': 26,
'Puducherry': 27,
'Punjab': 28,
'Rajasthan': 29,
'Sikkim': 30,
'Tamil Nadu': 31,
'Telangana': 32,
'Tripura': 33,
'Uttar Pradesh': 34,
'Uttarakhand': 35,
'West Bengal': 36}
st.set_page_config(layout = 'wide')
def VaccineCheck(state):
today = date.today()
current_date = today.strftime("%d-%m-%Y") ##Gets todays Date
st_id = str(state_index[state])
headers = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:85.0) Gecko/20100101 Firefox/85.0'}
district_url = "https://cdn-api.co-vin.in/api/v2/admin/location/districts/"+st_id
response = requests.get(district_url,headers = headers)
response
VaccineCheck('Kerala')
When running this on local Streamlit I get the response code 200. But when I run it online on Streamlit sharing, I get Error 403. Is it an issue with the headers? Please help.
Thank you!