Hi There. I'm trying to run the following using pycharm IDE (python 2.7). I however get a "400 Ba...

Jan
Jan Explorer

...d Request" error as per below. This error does not always occur, sometimes the exact same script runs fine. Please advise.

My Script:

df, err = ek.get_data(000001.SZ,000002.SZ,000030.KS,000039.SZ,000050.SZ,
TR.PriceClose.calcdate;
TR.EPSActValue(Period=FY - 3);
TR.EPSActValue(Period=FY - 2);
TR.EPSActValue(Period=FY - 1);
TR.EPSActValue(Period=FY0);
TR.EPSMean(Period=FY1);
TR.EPSMean(Period=FY2);
TR.EPSMean(Period=FY3);
TR.NumberOfAnalysts(Period=FY - 3);
TR.NumberOfAnalysts(Period=FY - 2);
TR.NumberOfAnalysts(Period=FY - 1);
TR.NumberOfAnalysts(Period=FY0);
TR.NumberOfAnalysts(Period=FY1);
TR.NumberOfAnalysts(Period=FY2);
TR.NumberOfAnalysts(Period=FY3);
TR.EPSMean(Period=FY - 3).periodenddate;
TR.EPSMean(Period=FY - 2).periodenddate;
TR.EPSMean(Period=FY - 1).periodenddate;
TR.EPSMean(Period=FY0).periodenddate;
TR.EPSMean(Period=FY1).periodenddate;
TR.EPSMean(Period=FY2).periodenddate;
TR.EPSMean(Period=FY3).periodenddate
,SDate=2017-01-01,EDate=2017-03-31,Frq=M)

Error I get:

Traceback (most recent call last):
File "/Users/richardtbenade/Repos/df_001/datapull.py", line 71, in <module>
df, err = ek.get_data(instrument_list_batch[k],get_command_string)
File "/Users/richardtbenade/virtualenvs/eikon/lib/python2.7/site-packages/eikon/data_grid.py", line 141, in get_data
result = eikon.json_requests.send_json_request(DataGrid_UDF_endpoint, payload, debug=debug)
File "/Users/richardtbenade/virtualenvs/eikon/lib/python2.7/site-packages/eikon/json_requests.py", line 82, in send_json_request
check_server_error(result)
File "/Users/richardtbenade/virtualenvs/eikon/lib/python2.7/site-packages/eikon/json_requests.py", line 130, in check_server_error
raise requests.HTTPError(error_message, response=server_response)
requests.exceptions.HTTPError: 400 Bad Request
Process finished with exit code 1

Best Answer

  • Alex Putkov.1
    Alex Putkov.1 ✭✭✭✭✭
    Answer ✓
    @Jan

    I'm afraid the method you're executing doesn't make sense to me on more than one level.
    The request example you provided has so many syntax errors, I don't see how it can possibly ever run fine. I have to assume that somehow the text must have been altered in transfer between IDE and your post here? Otherwise you'd be getting syntax errors instead of HTTP 400.
    Semantically why do you want to mix the last business day of the month between January and March 2017 (provided by TR.PriceClose.calcdate with {'SDate':'2017-01-01','EDate':'2017-03-31','Frq':'M'} parameters) with EPS estimates for the previous and the next 3 years? But assuming for whatever reason this is indeed what you want to retrieve, the correct syntax is:

    df, err = ek.get_data(['000001.SZ','000002.SZ','000030.KS','000039.SZ','000050.SZ'], ['TR.PriceClose.calcdate', 'TR.EPSActValue(Period=FY-3)', 'TR.EPSActValue(Period=FY-2)', 'TR.EPSActValue(Period=FY-1)', 'TR.EPSActValue(Period=FY0)', 'TR.EPSMean(Period=FY1); TR.EPSMean(Period=FY2)', 'TR.EPSMean(Period=FY3)', 'TR.NumberOfAnalysts(Period=FY-3)', 'TR.NumberOfAnalysts(Period=FY-2)', 'TR.NumberOfAnalysts(Period=FY-1)', 'TR.NumberOfAnalysts(Period=FY0)', 'TR.NumberOfAnalysts(Period=FY1)', 'TR.NumberOfAnalysts(Period=FY2)', 'TR.NumberOfAnalysts(Period=FY3)', 'TR.EPSMean(Period=FY-3).periodenddate', 'TR.EPSMean(Period=FY-2).periodenddate', 'TR.EPSMean(Period=FY-1).periodenddate', 'TR.EPSMean(Period=FY0).periodenddate', 'TR.EPSMean(Period=FY1).periodenddate', 'TR.EPSMean(Period=FY2).periodenddate', 'TR.EPSMean(Period=FY3).periodenddate'],{'SDate':'2017-01-01','EDate':'2017-03-31','Frq':'M'})

    I noticed in your example you have white spaces in some of the field level parameters, e.g. there are two spaces in TR.NumberOfAnalysts(Period=FY - 3). Not sure of you had them in your script, but these spaces will certainly result in HTTP 400 error.

Answers

  • zoya faberov
    zoya faberov ✭✭✭✭✭

    Hi @Jan,

    Would it be possible on your side to retest with Python 3.6?

    I can not be sure about this specific issue, but find that some unexpected behaviors stop manifesting with py 3.6.

    Thanks

  • Jan
    Jan Explorer

    Hi @zoya.farberov

    We've tried using Python 3.62 but get the same issue?