Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加自定义头后不能运行,不添加自定义头会被封 #5

Open
zky97 opened this issue Jun 3, 2019 · 5 comments
Open

Comments

@zky97
Copy link

zky97 commented Jun 3, 2019

import asyncio
import logging
from datetime import datetime
from aiowebsocket.converses import AioWebSocket
async def startup(uri,problem):
header=[
'GET wss://www.hfwh.top/ HTTP/1.1',
'Host: www.hfwh.top',
'Origin: https://www.woxunbudao.cn',
'Upgrade: websocket',
'Sec-WebSocket-Version: 13',
'Connection: Upgrade',
'Sec-WebSocket-Accept: g+8vNmGT8HaLHnj3QcQ/+0Nr5rM=',
]
async with AioWebSocket(uri,headers=header) as aws:
converse = aws.manipulator
Problem=problem
message = '{"type":1,"chars":"'+Problem+'"}'
print(message)
await converse.send(message)#发送数据
print('Client send: {message} \n'.format(message=Problem))
mes = await converse.receive()#接收数据
print('Client receive: {rec} \n'.format(rec=mes))
return mes
if name=='main':
remote='wss://www.hfwh.top/'
problem='科举中"殿试"的主考官是'
print(problem)
print(remote)
try:
asyncio.get_event_loop().run_until_complete(startup(remote,problem))
except KeyboardInterrupt as exc:
logging.info('Quit.')

@asyncins
Copy link
Owner

不能运行,指的是会报错吗?贴报错信息看一下

@zky97
Copy link
Author

zky97 commented Jun 26, 2019

直接就没显示也没报错,用你的带头的列子也是一样,直接没一点内容输出,也没报错,我用的是py3.7

@asyncins
Copy link
Owner

直接就没显示也没报错,用你的带头的列子也是一样,直接没一点内容输出,也没报错,我用的是py3.7

没有报错就是没问题。没有输出很有可能是目标网站还做了其他的验证,再检查一下。

@otccoin
Copy link

otccoin commented Sep 17, 2019

Traceback (most recent call last):
File "huobi-asyncio-ws.py", line 33, in
asyncio.get_event_loop().run_until_complete(startup(remote))
File "/Users/chengxuan/anaconda3/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "huobi-asyncio-ws.py", line 17, in startup
result=gzip.decompress(msg).decode('utf-8')
File "/Users/chengxuan/anaconda3/lib/python3.7/gzip.py", line 532, in decompress
return f.read()
File "/Users/chengxuan/anaconda3/lib/python3.7/gzip.py", line 276, in read
return self._buffer.read(size)
File "/Users/chengxuan/anaconda3/lib/python3.7/gzip.py", line 463, in read
if not self._read_gzip_header():
File "/Users/chengxuan/anaconda3/lib/python3.7/gzip.py", line 411, in _read_gzip_header
raise OSError('Not a gzipped file (%r)' % magic)
OSError: Not a gzipped file (b'\x03\xeb')
gzip报错啦,这个怎么处理?

@asyncins
Copy link
Owner

Traceback (most recent call last):
File "huobi-asyncio-ws.py", line 33, in
asyncio.get_event_loop().run_until_complete(startup(remote))
File "/Users/chengxuan/anaconda3/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "huobi-asyncio-ws.py", line 17, in startup
result=gzip.decompress(msg).decode('utf-8')
File "/Users/chengxuan/anaconda3/lib/python3.7/gzip.py", line 532, in decompress
return f.read()
File "/Users/chengxuan/anaconda3/lib/python3.7/gzip.py", line 276, in read
return self._buffer.read(size)
File "/Users/chengxuan/anaconda3/lib/python3.7/gzip.py", line 463, in read
if not self._read_gzip_header():
File "/Users/chengxuan/anaconda3/lib/python3.7/gzip.py", line 411, in _read_gzip_header
raise OSError('Not a gzipped file (%r)' % magic)
OSError: Not a gzipped file (b'\x03\xeb')
gzip报错啦,这个怎么处理?

这个错误源自于 asyncio 的源码,错误类型是 OSError,要想找到根本原因,你可能需要断点进入到源码中。但看文件名 gzip.py,我猜应该跟你传输的消息有关,也许是 Frames。这里我也没能给出具体的解决办法,只能为你提供查找线索的思路

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants