跑步
def function():
global global_values
global_values: str = []
Run Code Online (Sandbox Code Playgroud)
给出
SyntaxError: annotated name 'global_values' can't be global
Run Code Online (Sandbox Code Playgroud)
这有什么原因吗?
我无法使用websocketsmodule连接到 websocket 。我有以下代码:
import asyncio, ssl
import websockets
headers= {
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9',
'Cache-Control': 'no-cache',
'Connection': 'Upgrade',
'Host': ...,
'Origin': ...,
'Pragma': 'no-cache',
'Upgrade': 'websocket',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36'
}
async def hello():
uri = ...
async with websockets.connect(ssl=0,
extra_headers=headers,
origin="*",
uri = uri) as websocket:
pass
asyncio.get_event_loop().run_until_complete(hello())
Run Code Online (Sandbox Code Playgroud)
我得到以下异常:
Traceback (most recent call last):
File "C:\Users\AFMN\AppData\Local\Programs\Python\Python38-32\kr ws.py", line 30, in <module>
asyncio.get_event_loop().run_until_complete(hello())
File "C:\Users\AFMN\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line …Run Code Online (Sandbox Code Playgroud)