我收到以下错误:
Exception in thread Thread-3:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/Users/Matthew/Desktop/Skypebot 2.0/bot.py", line 271, in process
info = urllib2.urlopen(req).read()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
context=self._context)
File …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用来自Github(https://github.com/gto76/betbrain-scraper)的betbrain.py,它具有以下代码:
#!/usr/bin/python3
#
# Usage: betbrain.py [URL or FILE] [OUTPUT-FILE]
# Scrapes odds from passed betbrain page and writes them to
# stdout, or file if specified.
import os
import sys
import urllib.request
from bs4 import BeautifulSoup
from http.cookiejar import CookieJar
import parser_betbrain
import printer
DEFAULT_URL = 'https://www.betbrain.com/football/england/premier-league/#!/matches/'
# If no arguments are present, it parses the default page.
# Argument can be an URL or a local file.
def main():
html = getHtml(sys.argv)
soup = BeautifulSoup(html, "html.parser") …Run Code Online (Sandbox Code Playgroud) 如何在Tornado上设置WSS(Secure WebSockets)?
在他们的文档中,他们说以下内容:
WebSocketHandler.get_websocket_scheme可用于在未正确设置的情况下选择适当的URL方案(ws://或wss://) HTTPRequest.protocol.
那么,我如何使用get_websocket_scheme和/或HTTPRequest.protocol让WSS在Tornado上工作.
代码:
import websocket
ws = websocket.WebSocket()
ws.connect('wss://stream2.binance.com:9443/ws/!miniTicker@arr@3000ms')
record = ws.recv()
print(record)
Run Code Online (Sandbox Code Playgroud)
我试图从 Binance Websocket API 获取实时数据。尝试使用此示例 url 获取数据时
wss://stream.binance.com:9443/ws/bnbbtc@depth
Run Code Online (Sandbox Code Playgroud)
我收到此错误,表示 SSL 验证失败。
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)
Run Code Online (Sandbox Code Playgroud)
追溯:pastebin.com/RiHn025Z
我已经尝试过的:
所以我在SO How to create Python secure websocket client request?上发现了这个问题 并按照此代码的步骤进行操作
ws = websocket.WebSocket(sslopt={"cert_reqs": ssl.CERT_NONE})
ws.connect("wss://stream2.binance.com:9443/ws/!miniTicker@arr@3000ms")
Run Code Online (Sandbox Code Playgroud)
但随后发生了NameError:
NameError: name 'ssl' is not defined
Run Code Online (Sandbox Code Playgroud)
我尝试添加一个异常(这很荒谬,但仍然......),这导致了语法错误。
其他范围
我尝试使用不同的 websocket API,它使用 wss:// 但在第一个代码本身中工作得很好。
wss://ws.blockchain.info/inv
{"op":"ping"}
Run Code Online (Sandbox Code Playgroud)
状况:
我在 websockets.org 上尝试了 Echo 测试,wss url 功能齐全。
任何帮助将不胜感激。还有其他专门用于 binance 的模块,但我想要原始数据,所以我使用这个 api。
感谢您阅读我的问题。
websocket-client 的 GitHub URL:https …