question

Upvotes
Accepted
1 1 1 2

Potential bug issue with DSWS getting inconsistent results

Hi I am pulling historical price and yield information for a set of 6,068 bonds using the Datastream Enterprise API. I have defined a function (using previous suggestions here) to bypass the 50 instrument limit (picture 1).

When I run this code it works fine but I am getting inconsistent results each time. For example the results for Interest Yield (IY) the first time returned information on 5927 instruments, but the second time returned information on 6021 instruments. My code is exactly the same each run which makes me think that there is a bug issue that causes the data to change each time.

Has this issue been found before? Does anyone have any suggestions on how to fix this?

Capture1.PNG



pythondatastream-apidsws-api
capture1.png (28.0 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.

@vy.nguyen

Could you please share the list.txt file? Therefore, we can try to run it and verify the result.

@jirapongse.phuriphanvichai

See attached for list of bond symbols.

list.txt

list.txt (47.4 KiB)

Hi @vy.nguyen,

Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query?
If so please can you click the 'Accept' text next to the appropriate reply? This will guide all community members who have a similar question.

Thanks,
AHS


@vy.nguyen

Hi,

Please be informed that a reply has been verified as correct in answering the question, and marked as such.

Thanks,

AHS

Upvotes
Accepted
78.6k 248 52 74

@vy.nguyen

Thank you for the list.

I found that sometimes the server returned the error messages.

Object reference not set to an instance of an object.
MainframeAccessPoint error.Timed out waiting for activity from service.

Therefore, the code needs to check for it and then re-requests to get the data. I have modified the code, as shown below.

def load_data():
    dataframes_list = []
    for x in list_of_fields:
        print(x)
        print(tickers_of_interest_lst[0], 1)
        df = ds.get_data(tickers = tickers_of_interest_lst[0],
                        fields=[x],start='1992-01-31', end='2021-07-26').T
        print(df.shape)
        for i in tickers_of_interst_chunks:
            print(i[0],"...", i[len(i)-1], len(i))
            _df = ds.get_data(tickers = ','.join(i),
                              fields=[x],
                              start='1992-01-31', 
                              end='2021-07-26').T
            
            print(_df.shape)
            while _df.shape[0] < len(i):
                if "Value" in _df.index:
                    print(_df.loc["Value",0])
                print(i[0],"...", i[len(i)-1], len(i))
                _df = ds.get_data(tickers = ','.join(i),
                              fields=[x],
                              start='1992-01-31', 
                              end='2021-07-26').T
                print(_df.shape)
            
            df = df.append(_df)
            
        dataframes_list.append(df)
        
    return dataframes_list

It will re-request when the number of rows in the dataframe is not equal to the number of items in the request message.

Please be informed that it is just a sample code so it may not be able to cover all issues.

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 1 1 2
@jirapongse.phuriphanvichai 


Thanks much. In trying the code again, I'm still running into the error message below. Could you help troubleshoot further?


MPD 244YWE 1 (1, 7692) 2445GY ... 837KW6 50 (50, 7692) 819C6N ... 7058DJ 50 (50, 7692) 218062 ... 5961NV 50 (50, 7692) 2100AL ... 595739 50 (50, 7692) 60867W ... 7998WX 50 (50, 7692) 5601LW ... 646F3A 50 (50, 7692) 851GTP ... 783XFG 50 (50, 7692) 7994HJ ... 49020F 50 (50, 7692) 786KY8 ... 606NMD 50 (50, 7692) 801ZX6 ... 79882E 50 (50, 7692) 21834H ... 234A2E 50 (50, 7692) 206AAH ... 8607DZ 50 (50, 7692) 723278 ... 832GX5 50 (50, 7692) 232AZ2 ... 222CAC 50 (50, 7692) 607ZW6 ... 838XF0 50 (50, 7692) 633J2G ... 3678V4 50 (50, 7692) 797YL1 ... 5772VF 50 (50, 7692) 5771R8 ... 5772TW 50 (50, 7692) 5772T3 ... 5772V3 50 (50, 7692) 5771VE ... 5771UN 50 (50, 7692) 5771UX ... 818Z3A 50 (50, 7692) 22325A ... 231XVD 50 (50, 7692) 19445W ... 831X75 50 get_data : Exception Occured (<class 'requests.exceptions.SSLError'>, SSLError(MaxRetryError('HTTPSConnectionPool(host=\'product.datastream.com\', port=443): Max retries exceeded with url: /DSWSClient/V1/DSService.svc/rest/GetData (Caused by SSLError(SSLError("bad handshake: SysCallError(-1, \'Unexpected EOF\')")))')), <traceback object at 0x000001BECFBEE300>) None

Traceback (most recent call last):  File "c:\Users\vnguyen\ofrconda\lib\site-packages\urllib3\contrib\pyopenssl.py", line 485, in wrap_socket    cnx.do_handshake()  File "c:\Users\vnguyen\ofrconda\lib\site-packages\OpenSSL\SSL.py", line 1934, in do_handshake    self._raise_ssl_error(self._ssl, result)  File "c:\Users\vnguyen\ofrconda\lib\site-packages\OpenSSL\SSL.py", line 1664, in _raise_ssl_error    raise SysCallError(-1, "Unexpected EOF") OpenSSL.SSL.SysCallError: (-1, 'Unexpected EOF') 
During handling of the above exception, another exception occurred: 
Traceback (most recent call last):  File "c:\Users\vnguyen\ofrconda\lib\site-packages\urllib3\connectionpool.py", line 665, in urlopen    httplib_response = self._make_request(  File "c:\Users\vnguyen\ofrconda\lib\site-packages\urllib3\connectionpool.py", line 376, in _make_request    self._validate_conn(conn)  File "c:\Users\vnguyen\ofrconda\lib\site-packages\urllib3\connectionpool.py", line 994, in _validate_conn    conn.connect()  File "c:\Users\vnguyen\ofrconda\lib\site-packages\urllib3\connection.py", line 352, in connect    self.sock = ssl_wrap_socket(  File "c:\Users\vnguyen\ofrconda\lib\site-packages\urllib3\util\ssl_.py", line 370, in ssl_wrap_socket    return context.wrap_socket(sock, server_hostname=server_hostname) ssl.SSLError: ("bad handshake: SysCallError(-1, 'Unexpected EOF')",) 
During handling of the above exception, another exception occurred: 
Traceback (most recent call last):  File "c:\Users\vnguyen\ofrconda\lib\site-packages\requests\adapters.py", line 439, in send    resp = conn.urlopen(  File "c:\Users\vnguyen\ofrconda\lib\site-packages\urllib3\connectionpool.py", line 719, in urlopen    retries = retries.increment(  File "c:\Users\vnguyen\ofrconda\lib\site-packages\urllib3\util\retry.py", line 436, in increment    raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='product.datastream.com', port=443): Max retries exceeded with url: /DSWSClient/V1/DSService.svc/rest/GetData (Caused by SSLError(SSLError("bad handshake: SysCallError(-1, 'Unexpected EOF')"))) 
During handling of the above exception, another exception occurred: 
Traceback (most recent call last):  File "c:\Users\vnguyen\ofrconda\lib\site-packages\DatastreamDSWS\DS_Response.py", line 172, in get_data    json_Response = requests.post(getData_url, json=json_dataRequest,  File "c:\Users\vnguyen\ofrconda\lib\site-packages\requests\api.py", line 119, in post    return request('post', url, data=data, json=json, **kwargs)  File "c:\Users\vnguyen\ofrconda\lib\site-packages\requests\api.py", line 61, in request    return session.request(method=method, url=url, **kwargs)  File "c:\Users\vnguyen\ofrconda\lib\site-packages\requests\sessions.py", line 530, in request    resp = self.send(prep, **send_kwargs)  File "c:\Users\vnguyen\ofrconda\lib\site-packages\requests\sessions.py", line 643, in send    r = adapter.send(request, **kwargs) requests.exceptions.SSLError: HTTPSConnectionPool(host='product.datastream.com', port=443): Max retries exceeded with url: /DSWSClient/V1/DSService.svc/rest/GetData (Caused by SSLError(SSLError("bad handshake: SysCallError(-1, 'Unexpected EOF')")))

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-e76653d54b16> in <module>
----> 1 time_series = load_data()

<ipython-input-10-2899a03b5d0d> in load_data()
     18             print(i[0],"...", i[len(i)-1], len(i))
     19 ---> 20             _df = ds.get_data(tickers = ','.join(i),
     21                               fields=[x],
     22                               start='1992-01-31',

AttributeError: 'NoneType' object has no attribute 'T'
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.

@vy.nguyen

How often does the problem occur?

From the error message, it looks like to be a connection issue.

Exception Occured (<class 'requests.exceptions.SSLError'>, SSLError(MaxRetryError('HTTPSConnectionPool(host=\'product.datastream.com\', port=443): Max retries exceeded with url: /DSWSClient/V1/DSService.svc/rest/GetData (Caused by SSLError(SSLError("bad handshake: SysCallError(-1, \'Unexpected EOF\')")))')) 

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.