- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题的本质是我以前通过发送 Origin、User-Agent、Cookies 连接到 websocket 并且连接有效,现在域所有者决定将其更改为 websocket 的域并将 cloudflare 保护放在那里,之后我的连接方法不起作用。建议一些方法或有关如何使用 cloudflare 连接到 Web 套接字的信息。请帮帮我!!
我的代码示例:
import websocket
import json
import time
import traceback
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.173', 'cookie': '__cfduid=da97b059db0292806e2affdf9c3f4fd8b1593022325; _csrf=i8W6njc7hUXMOf4iQjiAxKg1; language=en; theme=darkTheme; pro_version=false; csgo_ses=1489162147d69debd9fe5d0ea2e445c87a117578d774502172d7151b89b82f7f; steamid=76561199068891508; avatar=https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/fe/fef49e7fa7e1997310d705b2a6158ff8dc1cdfeb_medium.jpg; username=andrewcrook232; thirdparty_token=06d04856ce6e334aa1368696df775e7ba0b1b898db135b0af0b5dc0fe001dd55; user_type=old; sellerid=6721648; type_device=desktop', 'origin': 'https://cs.money'}
def start_ws():
try:
ws = websocket.WebSocketApp("wss://ws.cs.money/ws", on_message = on_message, cookie = json.dumps(headers))
print("Connected")
while True:
ws.run_forever(ping_timeout=20)
print("Reload")
time.sleep(20)
except:
print(traceback.format_exc())
def on_message(ws, message):
try:
print(message)
except:
print(traceback.format_exc())
if __name__ == "__main__":
start_ws()
以下是我使用 Chrome Inspector (f12) -> Network -> WS -> headers 获得的所有信息,这些信息应该足以成功加入 WSS。
Request URL: wss://ws.cs.money/ws
Request Method: GET
Status Code: 101 Switching Protocols
alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400
CF-Cache-Status: DYNAMIC
CF-RAY: 5a886ad37f4b8ac6-KBP
cf-request-id: 038921182700008ac6798a2200000001
Connection: upgrade
Date: Wed, 24 Jun 2020 18:12:29 GMT
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Sec-WebSocket-Accept: zrH4CEKXm3BY5z77HroJDqGgYSc=
Server: cloudflare
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Upgrade: websocket
X-Content-Type-Options: nosniff
Accept-Encoding: gzip, deflate, br
Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7
Cache-Control: no-cache
Connection: Upgrade
Host: ws.cs.money
Origin: https://cs.money
Pragma: no-cache
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Key: GXVT8QewAgPEZDEZZ+x3dA==
Sec-WebSocket-Version: 13
Upgrade: websocket
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.173
还有额外的页面数据:
Request URL: https://cs.money/
Request Method: GET
Status Code: 200
Remote Address: 104.20.76.156:443
Referrer Policy: no-referrer-when-downgrade
alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400
cf-cache-status: DYNAMIC
cf-ray: 5a886ab5adac8aea-KBP
cf-request-id: 038921058800008aea96109200000001
content-encoding: br
content-security-policy: script-src 'self' cs.money dev.csgo.trade gleam.io www.am4charts.com translate.google.com translate.googleapis.com www.googletagmanager.com www.googleoptimize.com www.google-analytics.com connect.facebook.net https://vk.com 'unsafe-inline' top-fwz1.mail.ru 'unsafe-eval' api.usersnap.com cdn.usersnap.com cs.money mc.yandex.ru diffuser-cdn.app-us1.com diffuser-cdn.app-us1.com prism.app-us1.com trackcmp.net api.basisid.com https://cdn.amplitude.com sc-static.net support.cs.money embed-sandbox.bridgerpay.com embed.bridgerpay.com cs.money; worker-src 'self' data: blob: cs.money; object-src cs.money dota.money; media-src cs.money dota.money; frame-src cs.money dota.money onesignal.com https://*.com https://*.ru https://*.ua http://www.youtube.com
content-type: text/html; charset=utf-8
date: Wed, 24 Jun 2020 18:12:25 GMT
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
set-cookie: user_type=old; Path=/
set-cookie: language=en; Max-Age=8640000; Domain=cs.money; Path=/; Expires=Fri, 02 Oct 2020 18:12:25 GMT
set-cookie: language=en; Max-Age=8640000; Domain=.cs.money; Path=/; Expires=Fri, 02 Oct 2020 18:12:25 GMT
set-cookie: sellerid=6721648; Max-Age=8640000; Domain=cs.money; Path=/; Expires=Fri, 02 Oct 2020 18:12:25 GMT
set-cookie: pro_version=false; Max-Age=8640000; Domain=cs.money; Path=/; Expires=Fri, 02 Oct 2020 18:12:25 GMT
status: 200
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-cache-status: BYPASS
x-content-type-options: nosniff
x-dns-prefetch-control: off
x-download-options: noopen
x-frame-options: SAMEORIGIN
x-powered-by: PHP 4.1.0
x-xss-protection: 1; mode=block
:authority: cs.money
:method: GET
:path: /
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br
accept-language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7
cache-control: max-age=0
cookie: __cfduid=da97b059db0292806e2affdf9c3f4fd8b1593022325; _csrf=i8W6njc7hUXMOf4iQjiAxKg1; language=en; theme=darkTheme; pro_version=false; csgo_ses=1489162147d69debd9fe5d0ea2e445c87a117578d774502172d7151b89b82f7f; steamid=76561199068891508; avatar=https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/fe/fef49e7fa7e1997310d705b2a6158ff8dc1cdfeb_medium.jpg; username=andrewcrook232; thirdparty_token=06d04856ce6e334aa1368696df775e7ba0b1b898db135b0af0b5dc0fe001dd55; user_type=old; sellerid=6721648; type_device=desktop
referer: https://steamcommunity.com/openid/login?openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.return_to=https%3A%2F%2Fauth.dota.trade%2Flogin%2Fcallback%3FredirectUrl%3Dhttps%3A%2F%2Fcs.money%26callbackUrl%3Dhttps%3A%2F%2Fcs.money%2Flogin&openid.realm=https%3A%2F%2Fauth.dota.trade
sec-fetch-dest: document
sec-fetch-mode: navigate
sec-fetch-site: cross-site
sec-fetch-user: ?1
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.173
最佳答案
我不确定真正的原因,但您的代码似乎有一些错误。
如果您需要使用自定义 header 构建 websocket 连接,请将其传递给 header
参数,而不是 json 转储它。
ws = websocket.WebSocketApp("wss://ws.cs.money/ws",
on_message = on_message,
cookie = json.dumps(headers))
应该
cookie_string = headers['cookie']
del headers['cookie']
header_without_cookie = headers
ws = websocket.WebSocketApp("wss://ws.cs.money/ws",
on_message = on_message,
header = header_without_cookie,
cookie = cookie_string)
缺少 websocket-client 文档,也许您可以阅读有关用法的源代码
关于python - 在 python 上使用 cloudflare 保护连接到 websocket,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62561725/
独立访客总数与独立访客上限有何区别?为什么最大独立访客数小于总独立访客数?例如,在我网站的cloudflare报告中,总独立访客值是300,最大独立访客值只有55。 最佳答案 独立访客总数这是整个月的
如何在 Cloudflare 中添加域掩码?据我所知,Cloudfare 之前不允许这样做,但我不知道目前的状态。我想重定向一个带掩码的域。他们现在允许域掩码吗? 最佳答案 Cloudflare do
Cloud Flare、R2,如何上传图片? 我是 Cloud Flare 世界的新手, 我可以通过拖动上传图片,但是 如何使用编码上传图片?来自应用程序?? 我必须使用“WORKERS”
我正在使用 Cloudflare 来加速我的网站,它非常适合。不幸的是,我的一些用户需要将大于 Cloudflare 允许的最大值(即 300MB 大小)的视频上传到我的网站。有什么方法可以告诉 Cl
我正在使用 Cloudflare 来加速我的网站,它非常适合。不幸的是,我的一些用户需要将大于 Cloudflare 允许的最大值(即 300MB 大小)的视频上传到我的网站。有什么方法可以告诉 Cl
有问题,我在 cloudflare 中一直遇到。它说 - 身份验证错误(代码 10000) 登录到我的 cloudflare dashbord 时。 不知道为什么会这样,但是 我在谷歌上搜索了这个问题
我正在为我在 Google App Engine 上的应用程序开发后端系统。 我的应用程序和后端服务器与 json 通信。赞 http://server.example.com/api/check_s
我的 cloudflare 工作人员站点包含 React 应用程序获取的二进制数据。该二进制数据以 gzip 压缩形式存储,因为它压缩得非常好(我们谈论的是 20-25 倍的缩减,未压缩它太大而无法满
我正在尝试设置我的域以通过 Mailgun 和 Cloudflare 接收电子邮件,我认为我真的很接近但无法使其工作。 在 Mailgun 中,我已经验证了所有 DNS: 我认为问题出在 Cloudf
每次我访问使用 Cloudflare 的受攻击模式的网站时,它都会向我显示通常的文本,告诉我等待几秒钟,直到 Cloudflare 验证我不是机器人。每次我重新加载页面时,它都会更改我当前的 Ray
我只是有一个问题,我想获得访问者的 IP 地址。一切都很好,但一位用户只是给我 IPv6。这是我可以给你的代码,而且我刚刚安装了 cloudflare apache2 Mod。 $_SERVER['
我只是有一个问题,我想获得访问者的 IP 地址。一切都很好,但一位用户只是给我 IPv6。这是我可以给你的代码,而且我刚刚安装了 cloudflare apache2 Mod。 $_SERVER['
我们有一个匿名用户内容的网站,通常是静态的(每小时更新一次),并且每个用户的登录用户内容都不同,并且经常更新。 是否可以配置 cloudflare 以便为匿名用户缓存 HTML,但不为登录用户缓存,因
我正在查看 Cloudflare API在我们的 Cloudflare 帐户中获取域列表。 我从哪里获取 Cloudflare“X-Auth-Key”以便运行以下命令: curl.exe -X GET
我有以下 wrangler.toml .当我想使用 dev或 preview (例如 npx wrangler dev 或 npx wrangler preview )牧马人要求添加 preview_
我成功地根据以下内容使用无服务器框架部署了我的第一个 cloudflare Worker https://serverless.com/framework/docs/providers/cloudfl
Sveltekit和 Cloudflare似乎是一场伟大的比赛。我的目标是交付经过良好测试的代码,在 Cloudflare 页面/工作人员上顺利运行。为此,我使用 Cypress.io 进行端到端测试
我使用 traefik 作为我的自托管服务的反向代理,它就像一个魅力。每次我添加一个新服务时,traefik 都会检测到它并相应地路由查询。每个服务都路由到我的主域的子域。 我仍然需要做的唯一手动步骤
我遇到的问题是,我可以进入登录页面(在子域中)的唯一方法是当我为该记录关闭 cloudflare 时,当我打开 Cloudflare 时,它从不显示任何内容,一段时间后只显示ERR_CONNECT
我正在尝试为我的 Firebase 应用设置自定义域。 Firebase 托管网址:https://inventory-app-726af.firebaseapp.com/ 自定义域:inv.agsf
我是一名优秀的程序员,十分优秀!