when we use Eikon API, it shows the error message. Please tell us the cause of this error, thanks.
Hi @xuke ,
Thank you for reaching out to us.
I don't reproduced your issue but found where this exception is raised in httpx dependency.
We need more information on your script and how eikon lib is used so could you share your code (without any personal id, login or password) ?
Could you also provide which Python version you're using and check eikon + httpx versions with this code?
import eikonimport httpxprint(httpx.__version__)print(eikon.__version__)
On your side, you can test following code to check if it's failing too (it should run without error):
import asynciofrom sniffio import current_async_libraryasync def print_lib(): library = current_async_library() print("This is the current async lib: ", library)asyncio.run(print_lib())
def get_stock_commodity_code(request):success = True val = json.loads(request.body)code = val.get("code")date = val.get("date")return_dict = {'return_code': '200', 'return_info': 'success', 'result': False} set_rv_app_key() try: rd.open_session() df = rd.discovery.search( view=rd.discovery.Views.SEARCH_ALL,top=1,# filter="LocalFundCode in ('006038' '012728')", filter="TickerSymbol eq '" + code + "' and ExpiryDateString eq '" + date + "' and DerivedCategory eq 'Future'",select="DocumentTitle,RIC" )except Exception as result:errorMsg = str(result)loggers.error("get commodity info exception: " + str(result))success = False if success:df.columns = ['instrument', 'ricCode'] result_data = df.to_json()loggers.info("get commodity info response: " + result_data)# data.to_excel("C:\\dpp\\refinitive\\test\\stock.xlsx", sheet_name='Sheet1', index=False) return_dict['result'] = json.loads(result_data) else:return_dict['return_code'] = 500 return_dict['return_info'] = errorMsgreturn_dict['result'] = {}return HttpResponse(json.dumps(return_dict), content_type="application/json")
First of all, I didn't see that an error is logged before the AsynciolibraryNotFoundError !In previous lines, you should have some information similar to :
[2024-01-18 18:16:25,071;s] - [INFO] - [log] - Send GET request to http://127.0.0.1:9060/api/status to detect API Proxy...[2024-01-18 18:16:25,071;s] - [DEBUG] - [log] - Request to http://127.0.0.1:9060/api/status....
Could you share it ? (take care to remove your app key).Note that you'll find tips and tricks to check your environment (especially if Eikon API proxy is available) in Troubleshooting Userguide.
About your code, I reformat it:
def get_stock_commodity_code(request): success = True val = json.loads(request.body) code = val.get("code") date = val.get("date") return_dict = {"return_code": "200", "return_info": "success", "result": False} set_rv_app_key() try: rd.open_session() df = rd.discovery.search( view=rd.discovery.Views.SEARCH_ALL, top=1, # filter="LocalFundCode in ('006038' '012728')", filter="TickerSymbol eq '" + code + "' and ExpiryDateString eq '" + date + "' and DerivedCategory eq 'Future'", select="DocumentTitle,RIC", ) except Exception as result: errorMsg = str(result) loggers.error("get commodity info exception: " + str(result)) success = False if success: df.columns = ["instrument", "ricCode"] result_data = df.to_json() loggers.info("get commodity info response: " + result_data) # data.to_excel("C:\\dpp\\refinitive\\test\\stock.xlsx", sheet_name='Sheet1', index=False) return_dict["result"] = json.loads(result_data) else: return_dict["return_code"] = 500 return_dict["return_info"] = errorMsg return_dict["result"] = {} return HttpResponse(json.dumps(return_dict), content_type="application/json
My feedbacks:
@pf
we will accept your suggestion to try again
we will try to run program with this advises
you should manage the rd.open_session() on initializing your application, and close it (rd.close_session()) on closing your application.
set_rv_app_key() is called before rd.open_session() but according to your initial log, it's the inverse:Is this correct or are the logs out of order?
Hi,
I noticed that during initialization, the initial steps are failing.
Could you verify that your Eikon product is allowed for Python usage. In Help>About Refinitiv Eikon, APPS tab, you should find REFINITIVHOLDINGS.EIKON.DATAAPIPROXY app:
Then test http://localhost:9060/api/status to verify if the Data API Proxy was started successfully:
this is right
Your versions arn't recent:
It could explain why it's failing.Did it work before ?
You should contact your Account Manager to upgrade to Eikon 3.6.6 (it contains API Proxy 1.10.0.0).
@pf Thanks for your advice. We connect the support hotline, but failed to upgrade from Eikon 3.3.11 (Data API Proxy 1.9.0.0) to Eikon 3.6.6 (Data API Proxy 1.10.0.0). Below information for your reference.
Steps Done: Eikon had been uninstalled and reinstalled by PC Admin. 1. Ended Excel, Word, PPT and Eikon processes. 2. Uninstalled the obsolete version of Eikon from Windows Control Panel > Programs and Features. 3. Downloaded the latest version Eikon 4.0.64, installed Eikon 4.0.64 and VBA71 one by one with PC Admin. 4. Logged in Eikon 4.0.64 successfully. Checked the Data API Proxy version: it was showing Eikon 3.3.11 (Data API Proxy 1.9.0.0), failed to upgrade. 5. Referred to below link, tried the steps, the version still at Eikon 3.3.11 (Data API Proxy 1.9.0.0).
https://developers.lseg.com/en/api-catalog/eikon/eikon-data-api/tutorials#how-to-update-your-eikon-data-api