question

Upvotes
1 2 3 3

AttributeError: module 'anyio' has no attribute 'Lock'

Hi,


I face this error message when running python with eikon api today. The error message is module 'anyio' has no attribute 'Lock'. I have already downgraded the anyio version from 3.4.0 to 3.2.1, but the problem stays. How to solve this problem?


Thanks.





Python 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)]

Type "copyright", "credits" or "license" for more information.

IPython 7.22.0 -- An enhanced Interactive Python.

import sys

sys.path.append(r'C:\users\clli\python_prod\Lib\site-packages')

import holidays

from RAW_Daily_imports import dailyimport

from GlobeWatchlist import globe_returns

from CreateDailyPriceFile import dailypxfile

test=dailyimport(justdata=True)

Starting NAV import process

Starting FX import process

Master file script error

test=dailyimport(justdata=True,run_which=['Benchmark'])

Exception ignored in: <function Session.__del__ at 0x0000029390C70940>

Traceback (most recent call last):

File "C:\users\clli\python_prod\Lib\site-packages\eikon\streaming_session\session.py", line 237, in __del__

Session.unregister_session(self)

File "C:\users\clli\python_prod\Lib\site-packages\eikon\streaming_session\session.py", line 153, in unregister_session

raise EikonError('Error', 'Try to unregister unavailable session')

eikon.eikonError.EikonError: Error code Error | Try to unregister unavailable session

Master file script error

test=dailyimport(justdata=True,run_which=['Benchmark'])

Exception ignored in: <function Session.__del__ at 0x0000029390C70940>

Traceback (most recent call last):

File "C:\users\clli\python_prod\Lib\site-packages\eikon\streaming_session\session.py", line 237, in __del__

Session.unregister_session(self)

File "C:\users\clli\python_prod\Lib\site-packages\eikon\streaming_session\session.py", line 153, in unregister_session

raise EikonError('Error', 'Try to unregister unavailable session')

eikon.eikonError.EikonError: Error code Error | Try to unregister unavailable session

Master file script error

(1)

import eikon as ek # the Eikon Python wrapper package

import pandas as pd

ek.set_app_key('10e2f58ba50c4e58aa4ddde0c910e1f6a515c10e')

Exception ignored in: <function Session.__del__ at 0x0000029390C70940>

Traceback (most recent call last):

File "C:\users\clli\python_prod\Lib\site-packages\eikon\streaming_session\session.py", line 237, in __del__

Session.unregister_session(self)

File "C:\users\clli\python_prod\Lib\site-packages\eikon\streaming_session\session.py", line 153, in unregister_session

raise EikonError('Error', 'Try to unregister unavailable session')

eikon.eikonError.EikonError: Error code Error | Try to unregister unavailable session

Traceback (most recent call last):

File "<ipython-input-9-eae58f4994ba>", line 3, in <module>

ek.set_app_key('10e2f58ba50c4e58aa4ddde0c910e1f6a515c10e')

File "C:\users\clli\python_prod\Lib\site-packages\eikon\Profile.py", line 33, in set_app_key

get_profile().set_app_key(app_key)

File "C:\users\clli\python_prod\Lib\site-packages\eikon\Profile.py", line 223, in set_app_key

self._desktop_session = DesktopSession(app_key=app_key,

File "C:\users\clli\python_prod\Lib\site-packages\eikon\streaming_session\desktop_session.py", line 25, in __init__

super().__init__(app_key=app_key,

File "C:\users\clli\python_prod\Lib\site-packages\eikon\streaming_session\session.py", line 218, in __init__

self._http_session = httpx.AsyncClient(

File "C:\users\clli\python_prod\Lib\site-packages\httpx\_client.py", line 1380, in __init__

self._transport = self._init_transport(

File "C:\users\clli\python_prod\Lib\site-packages\httpx\_client.py", line 1428, in _init_transport

return AsyncHTTPTransport(

File "C:\users\clli\python_prod\Lib\site-packages\httpx\_transports\default.py", line 233, in __init__

self._pool = httpcore.AsyncConnectionPool(

File "C:\users\clli\python_prod\Lib\site-packages\httpcore\_async\connection_pool.py", line 111, in __init__

self._pool_lock = AsyncLock()

File "C:\users\clli\python_prod\Lib\site-packages\httpcore\_synchronization.py", line 12, in __init__

self._lock = anyio.Lock()

AttributeError: module 'anyio' has no attribute 'Lock'

eikoneikon-data-apirefinitiv-dataplatform-eikoneikon-for-officeeikon-desktop-data-apieikonapp
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
87.3k 294 53 79

@clli

You can try the following code.

import anyio
anyio.Lock()

Next, check the version of anyio in the C:\users\clli\python_prod\Lib\site-packages directory.

1639967577506.png


1639967577506.png (9.8 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
1 2 3 3

Thanks. Do you have any other recommended solution? I tried but I still face this issue.screen-shot-2021-12-19-at-220557.png

screen-shot-2021-12-19-at-220614.png


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
87.3k 294 53 79

@clli

My anyio-3.2.1 has the Lock attribute.

I found that anyio below 3.x (such as 2.2.0) doesn't have the Lock attribute.

You can check to code why the anyio doesn't have the Lock attribute.

import anyio
print(anyio.__file__)
print(open(anyio.__file__).read())

1639972923783.png

I assumed that you are still loading the old version of anyio.



1639972923783.png (47.7 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
1 2 3 3

Thanks. I did not see the Lock attribute in anyio. my anyio version is 3.2.1. I have attached the output here. Please assist with my next step. Thanks.


import anyio


anyio.Lock()

Traceback (most recent call last):


File "<ipython-input-7-891900de7013>", line 1, in <module>

anyio.Lock()


AttributeError: module 'anyio' has no attribute 'Lock'



print(anyio.__file__)

C:\ProgramData\Anaconda3\lib\site-packages\anyio\__init__.py


print(open(anyio.__file__).read())

__all__ = ('maybe_async', 'maybe_async_cm', 'run', 'sleep', 'current_time', 'get_all_backends',

'get_cancelled_exc_class', 'BrokenResourceError', 'BusyResourceError',

'ClosedResourceError', 'DelimiterNotFound', 'EndOfStream', 'ExceptionGroup',

'IncompleteRead', 'TypedAttributeLookupError', 'WouldBlock', 'AsyncFile', 'open_file',

'aclose_forcefully', 'open_signal_receiver', 'connect_tcp', 'connect_unix',

'create_tcp_listener', 'create_unix_listener', 'create_udp_socket',

'create_connected_udp_socket', 'getaddrinfo', 'getnameinfo', 'wait_socket_readable',

'wait_socket_writable', 'create_memory_object_stream', 'run_process', 'open_process',

'create_lock', 'create_condition', 'create_event', 'create_semaphore',

'create_capacity_limiter', 'open_cancel_scope', 'fail_after', 'move_on_after',

'current_effective_deadline', 'create_task_group', 'TaskInfo', 'get_current_task',

'get_running_tasks', 'wait_all_tasks_blocked', 'run_sync_in_worker_thread',

'run_async_from_thread', 'current_default_worker_thread_limiter',

'create_blocking_portal', 'start_blocking_portal', 'typed_attribute',

'TypedAttributeSet', 'TypedAttributeProvider')


from ._core._compat import maybe_async, maybe_async_cm

from ._core._eventloop import current_time, get_all_backends, get_cancelled_exc_class, run, sleep

from ._core._exceptions import (

BrokenResourceError, BusyResourceError, ClosedResourceError, DelimiterNotFound, EndOfStream,

ExceptionGroup, IncompleteRead, TypedAttributeLookupError, WouldBlock)

from ._core._fileio import AsyncFile, open_file

from ._core._resources import aclose_forcefully

from ._core._signals import open_signal_receiver

from ._core._sockets import (

connect_tcp, connect_unix, create_connected_udp_socket, create_tcp_listener, create_udp_socket,

create_unix_listener, getaddrinfo, getnameinfo, wait_socket_readable, wait_socket_writable)

from ._core._streams import create_memory_object_stream

from ._core._subprocesses import open_process, run_process

from ._core._synchronization import (

create_capacity_limiter, create_condition, create_event, create_lock, create_semaphore)

from ._core._tasks import (

create_task_group, current_effective_deadline, fail_after, move_on_after, open_cancel_scope)

from ._core._testing import TaskInfo, get_current_task, get_running_tasks, wait_all_tasks_blocked

from ._core._threads import (

create_blocking_portal, current_default_worker_thread_limiter, run_async_from_thread,

run_sync_in_worker_thread, start_blocking_portal)

from ._core._typedattr import TypedAttributeProvider, TypedAttributeSet, typed_attribute


# Re-export imports so they look like they live directly in this package

for key, value in list(locals().items()):

if getattr(value, '__module__', '').startswith('anyio.'):

value.__module__ = __name__


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

The file is similar to the __init__.py of anyio-2.2.0.

It uses the anyio from C:\ProgramData\Anaconda3\lib\site-packages directory. Please check the version of anyio in this C:\ProgramData\Anaconda3\lib\site-packages directory

Thanks. the no attribute 'Lock' issue is solved by moving the anyio 3.2.1 folder from the prod folder to the C:\ProgramData\Anaconda3\lib\site-package folder, but I faced another message - Check if Eikon Desktop or Eikon API Proxy is running. I have read the troubleshooting guide and show the output in an answer below. Should I downgrade my Eikon version, too? If so, please let me know which version I should downgrade to. Thanks.

Upvotes
27.9k 67 18 14

Hello @clli

I am noticed that the libraries are located on both "C:\users\<user>\python_prod\Lib\site-packages\" and "C:\ProgramData\Anaconda3\lib\site-packages\" location.

Could you create a new Conda environment, install the Eikon Data API library in that environment and re-test the issue? You can find more detail on the Isolated development environment section of the Setting up a Python development environment tutorial page.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
1 2 3 3


2021-12-20 12:02:17,383 P[12576] [MainThread 8708] Eikon Proxy not running or cannot be reached. Please read the documentation on troubleshooting

2021-12-20 12:02:17,384 P[12576] [MainThread 8708] error

Traceback (most recent call last):

File "C:\Cloud\Box\Sprott Asset$\SAM Performance and Analytics\Risk\Applications\Python\Eikon_TimeSeries.py", line 41, in eikon_ts

data = ek.get_timeseries(rics,

File "C:\users\clli\python_prod\Lib\site-packages\eikon\time_series.py", line 182, in get_timeseries

ts_result = eikon.json_requests.send_json_request(TimeSeries_UDF_endpoint, payload, debug=debug)

File "C:\users\clli\python_prod\Lib\site-packages\eikon\json_requests.py", line 149, in send_json_request

raise EikonError(401, error_msg)

eikon.eikonError.EikonError: Error code 401 | Eikon Proxy not running or cannot be reached. Please read the documentation on troubleshooting

2021-12-20 12:02:17,388 P[12576] [MainThread 8708] Eikon error

Traceback (most recent call last):

File "C:\Cloud\Box\Sprott Asset$\SAM Performance and Analytics\Risk\Applications\Python\Eikon_TimeSeries.py", line 41, in eikon_ts

data = ek.get_timeseries(rics,

File "C:\users\clli\python_prod\Lib\site-packages\eikon\time_series.py", line 182, in get_timeseries

ts_result = eikon.json_requests.send_json_request(TimeSeries_UDF_endpoint, payload, debug=debug)

File "C:\users\clli\python_prod\Lib\site-packages\eikon\json_requests.py", line 149, in send_json_request

raise EikonError(401, error_msg)

eikon.eikonError.EikonError: Error code 401 | Eikon Proxy not running or cannot be reached. Please read the documentation on troubleshooting

2021-12-20 12:02:17,392 P[12576] [MainThread 8708] error

Traceback (most recent call last):

File "C:\Cloud\Box\Sprott Asset$\SAM Performance and Analytics\Risk\Applications\Python\RAW_Daily_imports.py", line 72, in dailyimport

all_data['Benchmark']=benchimport(fi('5,12',filedate,db=db),filedate, justdata,db=db)

File "C:\Cloud\Box\Sprott Asset$\SAM Performance and Analytics\Risk\Applications\Python\Dataimport.py", line 105, in file_importer

file_dict[fn]=data['TimeSeries']

TypeError: 'NoneType' object is not subscriptable

2021-12-20 12:02:17,394 P[12576] [MainThread 8708] critical

Eikon data retrieval error

Master file script error


import eikon as ek # the Eikon Python wrapper package

import pandas as pd

#set up eikon app

ek.set_app_key('XXX')

2021-12-20 12:03:47,873 P[12576] [MainThread 8708] Error: no proxy address identified.

Check if Eikon Desktop or Eikon API Proxy is running.

2021-12-20 12:03:47,875 P[12576] [MainThread 8708] Error on handshake url http://127.0.0.1:None/api/handshake : UnsupportedProtocol("Request URL is missing an 'http://' or 'https://' protocol.")

2021-12-20 12:03:47,876 P[12576] [MainThread 8708] Error on handshake url http://127.0.0.1:None/api/handshake : UnsupportedProtocol("Request URL is missing an 'http://' or 'https://' protocol.")

2021-12-20 12:03:47,877 P[12576] [MainThread 8708] Port number was not identified, cannot send any request

import eikon as ek

print(ek.__version__)

1.1.14


I have a hard time to to connect Eikon API now, after changing the anyio version to 3.2.1 in the Anaconda folder. I followed the guide and my outputs are listed below. Please advise on my next steps. Thank you.


https://developers.refinitiv.com/en/article-catalog/article/eikon-data-api-python-troubleshooting-refinitiv

1. My Eikon Desktop version:4.0.55

2. My Eikon Data APIs version:1.1.14

3.Verify that Eikon Desktop is running properly and APIPROXY service is enabled: There imight be something wrong in the API Proxy file.


Arg: C:\Program Files (x86)\Thomson Reuters\Eikon\X\Bin\Eikonbox.exe C:\Users\clli\AppData\Local\Thomson Reuters\Eikon User\Cache\LibraryCache\Apps\REFINITIVHOLDINGS.EIKON.DATAAPIPROXY\1.4.0.2\index.js -TraceLevel=-1


These parts are fine.

{"statusCode":"ST_PROXY_READY","version":"3.1.0"}
{"port":9000,"mode":"eikon4","pid":17216,"hasSecure":true,"startedTime":"Mon Dec 20 2021 11:59:34 GMT-0500 (Eastern Standard Time)","subApps":[{"path":"/heap"},{"path":"/ping"},{"path":"/api"}]}
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
1 2 3 3

anyio misses another attribute called 'abc' now.

import eikon

ek.set_app_key('XXX')

2021-12-20 13:12:55,940 P[12576] [MainThread 8708] Reset a Desktop session with new app_key

2021-12-20 13:12:55,967 P[12576] [MainThread 8708] Send GET request to http://127.0.0.1:9060/api/status to detect API Proxy...

2021-12-20 13:12:55,971 P[12576] [MainThread 8708] Request to http://127.0.0.1:9060/api/status

headers = {'x-tr-applicationid': '10e2f58ba50c4e58aa4ddde0c910e1f6a515c10e'}

params = None

2021-12-20 13:12:55,978 P[12576] [MainThread 8708] HTTP request failed: AttributeError("module 'anyio' has no attribute 'abc'")

2021-12-20 13:12:55,981 P[12576] [MainThread 8708] Error on checking proxy url http://127.0.0.1:9060/api/status : AttributeError("module 'anyio' has no attribute 'abc'")

2021-12-20 13:12:55,984 P[12576] [MainThread 8708] Warning: file .portInUse was not found. Try to fallback to default port number.

2021-12-20 13:12:55,988 P[12576] [MainThread 8708] Try defaulting to port 9000...

2021-12-20 13:12:55,991 P[12576] [MainThread 8708] Send GET request to http://127.0.0.1:9000/api/status to detect API Proxy...

2021-12-20 13:12:55,993 P[12576] [MainThread 8708] Request to http://127.0.0.1:9000/api/status

headers = {'x-tr-applicationid': '10e2f58ba50c4e58aa4ddde0c910e1f6a515c10e'}

params = None

2021-12-20 13:12:56,000 P[12576] [MainThread 8708] HTTP request failed: AttributeError("module 'anyio' has no attribute 'abc'")

2021-12-20 13:12:56,017 P[12576] [MainThread 8708] Error on checking proxy url http://127.0.0.1:9000/api/status : AttributeError("module 'anyio' has no attribute 'abc'")

2021-12-20 13:12:56,019 P[12576] [MainThread 8708] Try defaulting to port 36036...

2021-12-20 13:12:56,021 P[12576] [MainThread 8708] Send GET request to http://127.0.0.1:36036/api/status to detect API Proxy...

2021-12-20 13:12:56,024 P[12576] [MainThread 8708] Request to http://127.0.0.1:36036/api/status

headers = {'x-tr-applicationid': '10e2f58ba50c4e58aa4ddde0c910e1f6a515c10e'}

params = None

2021-12-20 13:12:56,031 P[12576] [MainThread 8708] HTTP request failed: AttributeError("module 'anyio' has no attribute 'abc'")

2021-12-20 13:12:56,033 P[12576] [MainThread 8708] Error on checking proxy url http://127.0.0.1:36036/api/status : AttributeError("module 'anyio' has no attribute 'abc'")

2021-12-20 13:12:56,035 P[12576] [MainThread 8708] Error: no proxy address identified.

Check if Eikon Desktop or Eikon API Proxy is running.

2021-12-20 13:12:56,037 P[12576] [MainThread 8708] Try to handshake on url http://127.0.0.1:None/api/handshake...

2021-12-20 13:12:56,040 P[12576] [MainThread 8708] Request to http://127.0.0.1:None/api/handshake

headers = {'Content-Type': 'application/json', 'x-tr-applicationid': '10e2f58ba50c4e58aa4ddde0c910e1f6a515c10e'}

params = None

2021-12-20 13:12:56,042 P[12576] [MainThread 8708] HTTP request failed: UnsupportedProtocol("Request URL is missing an 'http://' or 'https://' protocol.")

2021-12-20 13:12:56,044 P[12576] [MainThread 8708] Error on handshake url http://127.0.0.1:None/api/handshake : UnsupportedProtocol("Request URL is missing an 'http://' or 'https://' protocol.")

2021-12-20 13:12:56,048 P[12576] [MainThread 8708] Error on handshake url http://127.0.0.1:None/api/handshake : UnsupportedProtocol("Request URL is missing an 'http://' or 'https://' protocol.")

2021-12-20 13:12:56,050 P[12576] [MainThread 8708] Port number was not identified, cannot send any request

2021-12-20 13:12:56,052 P[12576] [MainThread 8708] Received notification for closed streaming session 0

2021-12-20 13:12:56,054 P[12576] [MainThread 8708] Received notification for closed streaming session 0

2021-12-20 13:12:56,056 P[12576] [MainThread 8708] Init a Desktop session with new app_key


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
87.3k 294 53 79

@clli

First, we need to check if the Eikon API proxy is running properly by accessing the following URLs via a web browser.

The output looks like this:

1640058728185.png

Next, you need to set up a new virtual environment in Conda, as mentioned by my colleague. Then, install the Eikon library in that environment to verify what the problem is.


1640058728185.png (41.7 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.