question

Upvotes
Accepted
51 1 1 0

I am receiving the following error message after I register my app with reuters through the python API: AttributeError: 'NoneType' object has no attribute 'status_code' ... Has anyone had any experience with this error and how to fix it?

eikoneikon-data-apipythonworkspacerefinitiv-dataplatform-eikonworkspace-data-apiapierror
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.

Error Message:

AttributeError: 'NoneType' object has no attribute 'status_code'

The eikon version is 1.1.5

Python is 3.6

The lines of code that produce this error is:

import eikon as eik

eik.set_app_key('xxxxxxxxxxxxxx')

heads = eik.get_news_headlines('AAPL.O',count = 1)

error here ---^

Running this code with logger:

  1. import logging
  2. import eikon as ek
  3. print(ek.__version__)
  4. ek.set_app_key('<app_key>')
  5. ek.set_log_level(1)
  6. ek.get_news_headlines("AAPL.O",count=10)

I get the following error:

2020-09-01 10:34:56,339 P[4776] [MainThread 5192] HTTP request failed: RuntimeError('read() called while another coroutine is already waiting for incoming data',)
Upvotes
Accepted
21 0 0 0

Hi, not sure if I should open a separate thread, however I have also been getting exactly the same error message. I am using the 1.1.5 Eikon Data API version. I also tried the http3==0.6 workaround suggested in the post above without any luck. Is there an alternative workaround? Would updating to Python 3.7 fix this issue?

Thank you.

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.

Hi @Antonios.Antoniadis

I have been advised by the RDP Dev team that they were able to reproduce what appears to be the same issue (i.e. same error message etc) with Python 3.6 - but could not be reproduced with 3.7 and also that version 1.1.5 of the Eikon library has been tested + qualified with Python 3.7 (but not 3.6)

Therefore, if you are able to test with v3.7 please do so.

Hi, thanks for getting back to me. I just checked this internally and our IT policy prevents us from moving to Python 3.7 at least for another year. Could this fix be applied to Python 3.6?

@Antonios.Antoniadis

Eikon Data APIs Python library v1.1.6.post2 is now available from PyPI. We believe this version of the library addresses various connection problems some users experienced with Eikon Data APIs Python library v1.1.5. Could you update the version of Eikon Data APIs Python library on your machine to v1.1.6.post2 and reply back on this thread if it helped?

Thanks, looks like this has been resolved on my side.

When I upgraded to Python 3.7+ issue with current library was resolved.

Upvotes
39.4k 78 11 27

Would you mind including the line of code that raises this exception? Or even better include the full trace.

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
27.6k 67 18 14

Hello @michael-r.meyer

Could you please also let us know the version of Eikon data API that you are using? You can check the version dynamically via the following statement:

import eikon as ek
ek.__version__
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
25.4k 90 13 25

Hi @michael-r.meyer

Also, please confirm which version of Python you are using.


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
86.2k 292 53 79

@michael-r.meyer

Please try this code by setting the log level to 1.

import logging 
import eikon as ek 
print(ek.__version__) 
ek.set_app_key('<app_key>') 
ek.set_log_level(1) 
ek.get_news_headlines("AAPL.O",count=10)

You should see an exception. Please share the exception.


1598957623101.png (149.1 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.

Hi -

I set log level to 1 and get the following exception thrown:

1.1.5


2020-09-01 07:44:18,751 P[4776] [MainThread 5192] HTTP request failed: RuntimeError('read() called while another coroutine is already waiting for incoming data',)
Upvote
25.4k 90 13 25

Hi @michael-r.meyer

This may not be the exact same issue that you are facing - but an internal user had a very similar error message/ usage scenario and it was down to an incompatible version of http3 library when using Python 3.6

For that user, the following resolved the issue:

pip uninstall http3 
pip install http3==0.6

An alternative option would be to try Python 3.7 which the RDP library dev team advises they have validated and certified with this version.


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
86.2k 292 53 79

@michael-r.meyer

I got the same error when using Python 3.6.8 and http3-0.6.7.

2020-09-02 11:26:44,511 P[19616] [MainThread 9404] HTTP request failed: RuntimeError('read() called while another coroutine is already waiting for incoming data',)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\venvs\3.6.8\lib\site-packages\eikon\news_request.py", line 121, in get_news_headlines
    result = eikon.json_requests.send_json_request(News_Headlines_UDF_endpoint, payload, debug=debug)
  File "C:\venvs\3.6.8\lib\site-packages\eikon\json_requests.py", line 94, in send_json_request
    logger.debug('HTTP Response code: {}'.format(response.status_code))
AttributeError: 'NoneType' object has no attribute 'status_code'

You can try a workaround by using http3==0.6,as mentioned by my colleague.

pip uninstall http3 
pip install http3==0.6
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.

Upvote
51 1 1 0

Hi -

I found that installing Python 3.7 or above solved the problem. No error after that.


Thanks

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
41 1 0 1

Untitled1


NoneType object has no attribute status_code

I had this exact same issue and tracked it back to a timeout in the nest_asyncio.py dependency.

In [3]:
import eikon as ek

ek.__version__
Out[3]:
'1.1.5'

This is just a helper function to demonstrate the source code we're looking at.

In [8]:
import inspect

def show_source_code(module, start_line, end_line):
    source = inspect.getsource(module)
    lines = source.split("\n")
    num_lines = len(lines)
    if start_line > num_lines:
        return ""
    if end_line > num_lines:
        end_line = num_lines
    print("\n".join(lines[start_line:end_line]))

Within the eikon package there is a 'json_requests.py' module containing the function 'send_json_request'.

This request gets a response from calling a http_request method. However, if this request fails it'll get response = None (say a timeout).

When try: logger.debug is called in the final line below it'll attempt to reference the status_code attribute of None and throw an attribute error.

In [21]:
show_source_code(ek.json_requests, 84, 94)

            # build the request
            udf_request = {'Entity': {'E': entity, 'W': data} }
            logger.debug('Request:{}'.format(udf_request))
            response = profile._desktop_session.http_request(url=profile.get_url(),
                                                             method="POST",
                                                             headers={'Content-Type': 'application/json',
                                                                      'x-tr-applicationid': profile.get_app_key()},
                                                             json=udf_request)
            try:
                logger.debug('HTTP Response code: {}'.format(response.status_code))
In [23]:
None.status_code

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-23-be7a3e11c091> in <module>
----> 1 None.status_code

AttributeError: 'NoneType' object has no attribute 'status_code'

This sent me on a bit of a hunt for the underlying issue... I'll spare you the steps inbetween, but I ended up having to fiddle with the timeout variable in the nest_asyncio.py dependency.

In [27]:
import nest_asyncio
In [32]:
show_source_code(nest_asyncio, 71, 74)

        timeout = 0 if ready or self._stopping \
            else min(max(0, scheduled[0]._when - now), 10) if scheduled \
            else None

If left unaltered then we'll end up with the issue you're seeing.

In [1]:
APP_KEY = "..."
In [2]:
import eikon as ek

ek.set_app_key(APP_KEY)
In [3]:
ek.get_news_headlines("AAPL.O",count=10)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-4b16f70155ba> in <module>
----> 1 ek.get_news_headlines("AAPL.O",count=10)

C:\Anaconda2\envs\py36\lib\site-packages\eikon\news_request.py in get_news_headlines(query, count, date_from, date_to, raw_output, debug)
    119         payload.update({
  
  'dateTo': to_datetime(date_to).isoformat()})
    120 
--> 121     result = eikon.json_requests.send_json_request(News_Headlines_UDF_endpoint, payload, debug=debug)
    122 
    123     if raw_output:

C:\Anaconda2\envs\py36\lib\site-packages\eikon\json_requests.py in send_json_request(entity, payload, debug)
     92                                                              json=udf_request)
     93             try:
---> 94                 logger.debug('HTTP Response code: {}'.format(response.status_code))
     95                 logger.debug('HTTP Response: {}'.format(response.text))
     96             except UnicodeEncodeError as unicode_error:

AttributeError: 'NoneType' object has no attribute 'status_code'

And that's what I was seeing...

However, we can modify the code in nest_asyncio and it'll work. Yes, it's a hack, but it'll work until the devs clean things up.

I incremented the timeout as follows (by adding 3 extra lines at the end):

In [9]:
import inspect
import nest_asyncio

show_source_code(nest_asyncio, 71, 77)

        timeout = 0 if ready or self._stopping \
            else min(max(0, scheduled[0]._when - now), 10) if scheduled \
            else None
        if timeout is not None:
            if timeout > 0:
                timeout = 20

And if you try it again:

In [4]:
ek.get_news_headlines("AAPL.O",count=1)
Out[4]:
versionCreatedtextstoryIdsourceCode2020-09-23 19:53:50.8892020-09-24 06:05:51.489000+00:00Reuters Insider - The "no matter what" stocks:...urn:newsml: reuters.com:20200923:nRTV28VXrs:13NS:RTRS

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.