-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement/Bug Fix] Tiingo Backend Uses JSON Which Conflicts With Python Boolean Calls #600
Comments
@hydrosquall I'm not sure if you saw this note or not. |
Hi @GenusGeoff , thanks for the ping, I missed this previously. I don't have time to look into this right now, but I can give a pointer to anyone who might want to look into this:
https://docs.python-requests.org/en/master/user/quickstart/#passing-parameters-in-urls
tiingo-python/tiingo/restclient.py Lines 47 to 50 in b4b42b9
One could take the The |
I did a test with Requests: Python 3.8.10 (default, May 19 2021, 13:12:57) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
At least with Version 2.25.1 of the Requests module, the keys and pairs are entered directly. I'll look to see if there's a way to modify such behavior internal to Requests as that would be the best answer. If that isn't possible then we'll need a hacky workaround to search if any of the values are Python Boolean and convert them to JSON Boolean. |
I'm unsure if this is an efficient answer, but a simple answer is to loop through the params dictionary keys and values and make a simple substitution, e.g.
Clearly, this can be made into a lambda expression or written in any of many ways to be far more efficient, but I wrote it in a very verbose format to clearly illustrate the pseudo-code. This is the output from printing a loop of the keys and values:
|
@GenusGeoff , this looks pretty good, thanks for looking into this and finding an initial solution. I think if you want to try introducing it, it could be done through the tiingo-python/tiingo/restclient.py Lines 47 to 50 in 11b8e45
import json
def format_params(params):
new_params = {}
for key in params:
new_params[key] = json.dump(params[key])
return new_params
# meanwhile, in restclient.py
formatted_params = format_params(params)
requests.request(# previous code,
params=formatted_params,
) |
Description
Made a call to IEX Intraday data enabling the "&afterHours=True" parameter. The problem is with the Pythonic need for True and False to be capitalized which conflicts with JSONs need to use "true" and "false" lowercase.
I expected the API call to return fruitful but instead returned None.
What I Did
I suggest that we utilize a JSON.dump(url_parameters) going forward to be better able to adapt to changes in the Tiingo API. A simple function could be created that is called before returning the URL string to the requests library.
Please see an excerpt from an email exchange from @tiingo:
@tiingo response:
I believe it's only a matter of time, as in my attempted enhancement, before the V2 API or later functionality exposes this "bug" in the code.
The text was updated successfully, but these errors were encountered: