0

I keep getting the StopIteration note when performing my code, my output is just to test if the code works as the whole thing involves retrieving data using an api. My code is showed as followed:

import pandas as pd
import json
import requests
from socketIO_client import SocketIO

TRADING_API_URL = 'https://api-demo.fxcm.com:443'
WEBSOCKET_PORT = 443

ACCESS_TOKEN = "ba08382c61b2b35f258e8ea64dcf4928c4263053"

def on_connect():
    print('websocket Connected: ' + socketIO._engineIO_session.id)   
def on_close():
    print('websocket Closed.')
    
socketIO = SocketIO(TRADING_API_URL, WEBSOCKET_PORT, params={'access_token': ACCESS_TOKEN})

socketIO.on('connect', on_connect)
socketIO.on('disconnect', on_close)

Bearer_access_token = "Bearer " + socketIO._engineIO_session.id + ACCESS_TOKEN

print(Bearer_access_token)

The notes I get are below:

---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_26108/1749199291.py in <module>
     14     print('websocket Closed.')
     15 
---> 16 socketIO = SocketIO(TRADING_API_URL, WEBSOCKET_PORT, params={'access_token': ACCESS_TOKEN})
     17 
     18 socketIO.on('connect', on_connect)

~\anaconda3\lib\site-packages\socketIO_client\__init__.py in __init__(self, host, port, Namespace, wait_for_connection, transports, resource, hurry_interval_in_seconds, **kw)
    349         self._callback_by_ack_id = {}
    350         self._ack_id = 0
--> 351         super(SocketIO, self).__init__(
    352             host, port, Namespace, wait_for_connection, transports,
    353             resource, hurry_interval_in_seconds, **kw)

~\anaconda3\lib\site-packages\socketIO_client\__init__.py in __init__(self, host, port, Namespace, wait_for_connection, transports, resource, hurry_interval_in_seconds, **kw)
     52         if Namespace:
     53             self.define(Namespace)
---> 54         self._transport
     55 
     56     # Connect

~\anaconda3\lib\site-packages\socketIO_client\__init__.py in _transport(self)
     60         if self._opened:
     61             return self._transport_instance
---> 62         self._engineIO_session = self._get_engineIO_session()
     63         self._negotiate_transport()
     64         self._connect_namespaces()

~\anaconda3\lib\site-packages\socketIO_client\__init__.py in _get_engineIO_session(self)
     73                 self._http_session, self._is_secure, self._url)
     74             try:
---> 75                 engineIO_packet_type, engineIO_packet_data = next(
     76                     transport.recv_packet())
     77                 break

StopIteration: 

Is there anything I can add (or take away) from my code to help stop this issue, without affecting the desired output? Thanks

  • If you search the existing questions there are a large number of answered ones, including: [python: socketio-client not working](https://stackoverflow.com/questions/45192699/python-socketio-client-not-working). The common thread seems to be library version mismatches. – Kemp Oct 10 '22 at 16:21
  • Hi, I have which is why I'm asking myself as most seem to be using the next() function but my code isn't. Can't get a clear idea of how to fix my code specifically – kiestuthridge23 Oct 10 '22 at 18:43
  • The one I linked has your exact stack trace doing the same thing as you with the same library as you, as do several others I found in my quick search. Have you looked in to whether their solution will work for you? – Kemp Oct 11 '22 at 08:53

0 Answers0