AttributeError: module 'websocket' has no attribute 'create_connection' websocket 爬蟲


抓取某個網站的數據,代碼如下

  

instrument_name = "BTC-25JUN21-28000-P"
    msg = {
        "jsonrpc": "2.0",
        "id": 3983,
        "method": "public/get_last_trades_by_instrument_and_time",
        "params": {
            "instrument_name": instrument_name,
            "start_timestamp": 1622822400000,
            "end_timestamp": 1623427200000,
            "count": 1000
        }
    }

    headers = {
        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1'
    }
    url = 'wss://test.deribit.com/ws/api/v2' ws = websocket.create_connection(url=url, headers=headers, timeout=15)
    ws.send(json.dumps(msg))
    print(ws.recv())

報錯如下

  

C:\Python37\python3.exe D:/spider_telegram/spider_17_deribit/spider_2_get_content.py
Traceback (most recent call last):
File "D:/spider_telegram/spider_17_deribit/spider_2_get_content.py", line 35, in <module>
spider()
File "D:/spider_telegram/spider_17_deribit/spider_2_get_content.py", line 28, in spider
ws = websocket.create_connection(url=url, headers=headers, timeout=15)
AttributeError: module 'websocket' has no attribute 'create_connection'

 

解決辦法:

  pip3 install   websocket-client

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM