Reputation: 53
use the below code for connect websocket to kucoin exchange in pythonanywhere
import websocket
import requests
base_url = 'https://api.kucoin.com'
public_url_request = '/api/v1/bullet-public'
response = requests.post(base_url+public_url_request)
response_json = response.json()
token = response_json['data']['token']
end_point = response_json['data']['instanceServers'][0]['endpoint']
url_websocket = end_point + '?' + 'token=' + token
ws = websocket.create_connection(url_websocket)
print(ws.recv())
when run this code in my pc it's ok but when run in pythonanywhere receive this error:
raise WebSocketProxyException( websocket._exceptions.WebSocketProxyException: failed CONNECT via proxy status: 403
for websocket in kucoin first need to request and receive token. in this example websocket url=wss://ws-api.kucoin.com/endpoint?token=2neAiuYvAU61ZDXANAGAsiL4-iAExhsBXZxftpOeh_55i3Ysy2q2LEsEWU64mdzUOPusi34M_wGoSf7iNyEWJ-3A4b43Ywb3cgwf791yIZ9hw2RDfWICHtiYB9J6i9GjsxUuhPw3BlrzazF6ghq4L3TV21Wn2BhYdwCTcPMlmUw=.LT6TMHw9TEabisQiSNA_qQ==
note: api.kucoin.com is in the whitelist
Upvotes: 0
Views: 616
Reputation: 5867
Free accounts on PythonAnywhere can only access sites on a whitelist. If the site that you're trying to connect to is an official public API, then it may be possible to add it to the list -- contact PythonAnywhere support, providing a link to the API docs.
Upvotes: 0