python 中request库
python 中request库可以修改websocket的hearders吗?有没有现成的代码可以学习一下呢?有木有大佬可以提供一下,,萌新想学习学习下。 本帖最后由 suchocolate 于 2021-5-12 16:21 编辑
from urllib import request
headers = {'User-Agent': 'Firefox'}
req = request.Request('http://httpbin.org/get', headers=headers)
r = request.urlopen(req)
print(r.read().decode('utf-8'))
import requests
headers={'User-Agent': 'Mozilla/5.0'}
r=requests.get('http://httpbin.org/get',headers=headers)
print('status code is ' + str(r.status_code))
print(r.text)
https://github.com/Python3WebSpider/Python3WebSpider suchocolate 发表于 2021-5-12 16:19
https://github.com/Python3WebSpider/Python3WebSpider
谢谢大佬 最终测试了下,,另外的办法:
import json
from websocket import create_connection
from urllib import request
url = 'ws://192.168.1.55:18086/wss/180476935254577485/99d39a4c-17c1-4217-8acb-1f8989fbc83a'
#websocket.enableTrace(True)
while True:
ws = create_connection(url,
header=["x-token:99d39a4c-17c1-4217-8acb-1f8989fbc83ax",
"x-tenant:T0014",
"x-server:1026"]
)
data =input('输入传输消息:')
# new_data=json.dumps(data,ensure_ascii=False)
ws.send(data)
print('收到回复消息:',ws.recv())
if data == 'q':
ws.close()
break
页:
[1]