python-3.x Graphql和Stake.com,POST主体丢失,内容类型无效,或者JSON对象没有键

f1tvaqid  于 2022-12-01  发布在  Python
关注(0)|答案(2)|浏览(181)

请帮帮忙。我正在使用刮刀绕过云耀斑。开发实时数据解析器的任务,卡在请求阶段...:(
`

headers = {
    "accept": "*/*",
    "accept-encoding": "gzip, deflate, br",
    "accept-language": "ru-RU,ru;q=0.9,en-GB;q=0.8,en;q=0.7,en-US;q=0.6",
    "cf-device-type": "",
    "content-length": "3315",
    "content-type": "application/json",
    "cookie": "session_info=undefined; currency_currency=btc; currency_hideZeroBalances=false; currency_currencyView=crypto; currency_bankingCurrencies=[]; casinoSearch=['Monopoly','Crazy Time','Sweet Bonanza','Money Train','Reactoonz']; sportsSearch=['Liverpool FC','Kansas City Chiefs','Los Angeles Lakers','FC Barcelona','FC Bayern Munich']; oddsFormat=decimal; sportMarketGroupMap={}; locale=ru; intercom-id-cx1ywgf2=86f79ef7-ca71-4205-8f41-b73b0b559b2e; intercom-session-cx1ywgf2=; cookie_consent=true; leftSidebarView_v2=minimized; sidebarView=hidden; cf_clearance=6420a111bb498d49b56800690b298b7bba53e91d-1667643880-0-150; __cf_bm=cj_pRlIaag.zmXOLQPWJ0GEip_W3NuRcjBa.OlOvIzU-1667643883-0-Ad3+LGxBsAD+n4k5G6mVTfRhfqAthNtU9O9VY4MicOoFQ82/DvoS6h44JXKfexV2niXlGcEBTEMB9VUOYiNbr/2tr1EidvV2unVIk7hyX8cYAcc0btV2eZv1yvPZEcGumjKYXvKuFJOx/vPpi53NXizPc8apm56HvNxb9SkKULIy",
    "dnt": "1",
    "origin": "https://stake.com",
    "referer": "https://stake.com/sports/home",
    "sec-ch-ua": "'Google Chrome';v='107', 'Chromium';v='107', 'Not=A?Brand';v='24'",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "Windows",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36",
    "x-forwarded-for": "88.99.58.45, 162.158.38.53, 172.20.242.28",
    "x-geoip-country": "DE",
    "x-geoip-state": "",
    "x-language": "ru"
}

body = """
    query highrollerSportBets($limit: Int!) {
        highrollerSportBets(limit: $limit) {
            ...RealtimeSportBet
            __typename
        }
    }
    
    fragment RealtimeSportBet on Bet {
        id
        iid
        bet {
            __typename
            ... on PlayerPropBet {
                ...PlayerPropBetFragment
                __typename
            }
            ... on SportBet {
                outcomes {
                    fixture {
                        data {
                            __typename
                            ... on SportFixtureDataMatch {
                                competitors {
                                    name
                                    abbreviation
                                    __typename
                                }
                                __typename
                            }
                        }
                        tournament {
                            category {
                                sport {
                                    slug
                                    __typename
                                }
                                __typename
                            }
                            __typename
                        }
                        __typename
                    }
                    __typename
                }
                createdAt
                potentialMultiplier
                amount
                currency
                user {
                    id
                    name
                    __typename
                }
                __typename
            }
        }
    }
    
    fragment PlayerPropBetFragment on PlayerPropBet {
        __typename
        active
        amount
        cashoutMultiplier
        createdAt
        currency
        customBet
        id
        odds
        payout
        payoutMultiplier
        updatedAt
        status
        user {
            id
            name
            __typename
        }
        playerProps {
            id
            odds
            lineType
            playerProp {
                ...PlayerPropLineFragment
                __typename
            }
            __typename
        }
    }
    
    fragment PlayerPropLineFragment on PlayerPropLine {
        id
        line
        over
        under
        suspended
        balanced
        name
        player {
            id
            name
            __typename
        }
        market {
            id
            stat {
                name
                value
                __typename
            }
            game {
                id
                fixture {
                    id
                    name
                    status
                    eventStatus {
                        ...FixtureEventStatus
                        __typename
                    }
                    data {
                        ... on SportFixtureDataMatch {
                            __typename
                            startTime
                            competitors {
                                ...CompetitorFragment
                                __typename
                            }
                        }
                        __typename
                    }
                    tournament {
                        id
                        category {
                            id
                            sport {
                                id
                                name
                                slug
                                __typename
                            }
                            __typename
                        }
                        __typename
                    }
                    __typename
                }
                __typename
            }
            __typename
        }
    }
    
    fragment FixtureEventStatus on SportFixtureEventStatus {
        homeScore
        awayScore
        matchStatus
        clock {
            matchTime
            remainingTime
            __typename
        }
        periodScores {
            homeScore
            awayScore
            matchStatus
            __typename
        }
        currentServer {
            extId
            __typename
        }
        homeGameScore
        awayGameScore
        statistic {
            yellowCards {
                away
                home
                __typename
            }
            redCards {
                away
                home
                __typename
            }
            corners {
                home
                away
                __typename
            }
            __typename
        }
    }
    
    fragment CompetitorFragment on SportFixtureCompetitor {
        name
        extId
        countryCode
        abbreviation
    }
"""
operationName = "highrollerSportBets"
variables = {"limit":10}

url = 'https://stake.com/_api/graphql'
sa_key = '280a2b7336344a8ea15106dd3220cc5a'
sa_api = 'https://api.scrapingant.com/v2/general'
qParams = {'url': url, 'x-api-key': sa_key}
reqUrl = f'{sa_api}?{urllib.parse.urlencode(qParams)}'

r = requests.post(url=reqUrl, json={"query": body, "operationName": operationName, "variables": variables}, headers=headers)
print(r.text)

`
输出量
POST主体缺失、内容类型无效或JSON对象没有键。
请告诉我,我在哪里犯了错误?也许有一些类似任务的库?
我正在使用VPN。必须传递cookie

fnvucqvd

fnvucqvd1#

注意:切勿发布任何API密钥
我可以运行你的代码没有错误。

import requests
from urllib.parse import urlencode
...
operationName = "highrollerSportBets"
variables = {"limit":10}

url = 'https://stake.com/_api/graphql'
sa_key = 'xxxx'
sa_api = 'https://api.scrapingant.com/v2/general'
qParams = {'url': url, 'x-api-key': sa_key}
reqUrl = f'{sa_api}?{urlencode(qParams)}' # just change this

print(reqUrl)
r = requests.post(url=reqUrl, json={"query": body, "operationName": operationName, "variables": variables}, headers=headers)
print(r.text)

执行

$ python3 --version
Python 3.10.6

$ python3 so.py 
https://api.scrapingant.com/v2/general?url=https%3A%2F%2Fstake.com%2F_api%2Fgraphql&x-api-key=XXX
{"detail":"Our browser was detected by target site. Try again later or contact us support@scrapingant.com"}
vwoqyblh

vwoqyblh2#

我也是一个Stake.com玩家,我每天都使用API(和VPN)来自动化一些下注。
要绕过cloudflare,您只需要获取一个名为“cf_clearance”的cookie,然后使用它请求。

request_data = {
    "query": body,
    "variables": {"limit": 20,"offset": 0},
}

cookies = {"cf_clearance": cf_clearance_value}  
session = requests.Session()
session.headers["x-access-token"] = "xxxx"
session.headers["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
time.sleep(1)
response = session.post("https://stake.com/_api/graphql", cookies=cookies,json=request_data)

相关问题