Jordan
Jordan

Reputation: 7

Python script works on jupyter notebook but not on local

the code is working fine in replit.com and jupyter notebook but doesn't work on my local env.

I don't understand why. it either say : name 'elem' is not defined (line 61) or Empty DataFrame Columns: [price] Index: [].

the code :

...


url = "https://www.bitmex.com/api/v1/trade"
filters = {
    'startTime':  td 
}
params = {
    'symbol': '.BVOL24H',
    'filter': json.dumps(filters),
}
response = requests.get(url, params=params)


bvol24_list = []
for elem in response.json():

    elem['timestamp'] = pd.to_datetime(elem['timestamp'], format="%Y-%m-%d %H:%M")
    mins = elem['timestamp'].strftime("%Y-%m-%d %H:%M")
    bvol24_list.append([elem['price'], mins])



vol_df = pd.DataFrame(data=bvol24_list, columns=['price', 'timestamp'])
vol_df = vol_df.set_index('timestamp')
print(elem['symbol'])
print(vol_df)

it does work fine on jupyter notebook:

.BVOL24H
              price
timestamp              
2021-12-27 17:15   1.97
2021-12-27 17:20   1.97
...
2021-12-27 18:10   1.99

Edit : it didn't work because of the different timezone and the delta applied on it, the list was empty because it couldn't get the data so the local variable was referenced "before assignment".

Upvotes: 0

Views: 288

Answers (1)

que
que

Reputation: 121

You could try to determine if "requests.get(url, params=params)" returns the expected values. Start by looking at the status_code of the response:

response.status_code

If the code is anything other than 200, there is likely a problem with the call itself.

If the code is 200, check to see what is actually contained in the response:

print(response.json())

Upvotes: 1

Related Questions