Error message not displaying when invalid currency specified
Closed this issue · 7 comments
My Python skills are virtually non-existent so I do not have a solution to offer up at the moment. Perhaps html needs to be defined as a global variable?
Executing:
python2 coinmarketcap_usd_history.py bitcoin 2017-01-01 2017-12-31 > btc.csv
returns....
Traceback (most recent call last):
File "coinmarketcap_test.py", line 181, in <module>
df = main()
File "coinmarketcap_test.py", line 169, in main
html = download_data(currency, start_date, end_date)
File "coinmarketcap_test.py", line 92, in download_data
return html
UnboundLocalError: local variable 'html' referenced before assignment
Something doesn't look right; your output references coinmarketcap_test.py
, rather than the the (correct) coinmarketcap_usd_history.py
invoked by your command.
Is coinmarketcap_test.py
a local modified version? If so, are you sure the problem still occurs with coinmarketcap_usd_history.py
?
I'm running python 2.7.10. Is your python2 the same version?
Python 2.7.14. I had made a copy of the original script after receiving the error with the original coinmarketcap_test.py, in an effort to research the issue without corrupting the original script.
So, I do not think the issue is a problem with the variable html. If a currency (coin) does not match on coinmarketcap, for example, ambrosus is listed as amber in the url (coinmarketcap.com/currencies/amber/) , so executing the script:
python2 coinmarketcap_usd_history.py ambrosus 2018-01-01 2018-01-27 > amb.csv
I expected an error based on these lines in the script:
except Exception as e: print('Error fetching price data from ' + url) print('Did you use a valid CoinMarketCap currency?\nIt should be entered exactly as displayed on CoinMarketCap.com (case-insensitive), with dashes in place of spaces.')
but instead it is returning:
Traceback (most recent call last): File "coinmarketcap_usd_history.py", line 180, in <module> df = main() File "coinmarketcap_usd_history.py", line 168, in main html = download_data(currency, start_date, end_date) File "coinmarketcap_usd_history.py", line 91, in download_data return html UnboundLocalError: local variable 'html' referenced before assignment
The script executes without issue when changing 'ambrosus' to 'amber'
Sorry to bother you, this is really my limited Python knowledge showing. I should have caught the issue on my end, but bit off on the variable referenced before assignment.
OK, so... the issue is just the lack of error message then? Am I understanding you correctly?
(I was not able to replicate the issue using the command you pasted in the original post)
Yes, the error message:
except Exception as e: print('Error fetching price data from ' + url) print('Did you use a valid CoinMarketCap currency?\nIt should be entered exactly as displayed on CoinMarketCap.com (case-insensitive), with dashes in place of spaces.')
if it is suppose to trigger for an incorrect spelling of the currency, did not trigger, but returned the UnboundLocal Error.
Perhaps, the difference between Python 2.7.14 and 2.7.10? At any rate, the script works pretty well. Thanks for taking the time to make it.
Ah, got it. Thanks for reporting it! And glad you found the tool helpful.
I don't have time to take a look at the fix but I'll clarify the issue and leave it here in case someone wants to submit a PR.