have a file tmodule.py contains a dictionary of URL's.when try to call it with specific URL id, get an error.
code looks like below:
import pandas as pd
import csv
import requests
def stock(self, stockname="", value=100):
stocknames = {
"ABAD1": "59612098290740355",
"ABDI1": "49054891736433700",
}
urlid = stocknames[stockname]
url = 'http://.............................&i=' + urlid
content = requests.get(url)
with open('out.csv', 'w') as f:
writer = csv.writer(f)
for line in content.iter_lines():
writer.writerow(line.decode('utf-8').split(','))
df = pd.read_csv('out.csv')
return (....)
above code has no error but when i try to pass a key like:
import tmodule as tm
st=tm.stock("ABAD1")
got this error :
File "D:\anaconda\envs\geo_env\Lib\site-packages\..........", line 323, in stock
urlid = stocknames[stockname]
KeyError: ''
it's a long dictionary and i just copy two key and value here