python中Post请求的研究进展

2024-10-01 22:41:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图编写一个python脚本,从这个页面获取My profile数据:https://turo.com/us/en/login 在firefox中使用f12,我得到了头,请求负载,请求负载的表单数据(请求体)

这是我的电子邮件地址、密码和主要api url:

密码:udannamondaypaul@gmail.com

用户名:udannamondaypaul@gmail.com

post请求的api url:https://turo.com/api/login

使用firefox登录时,我会得到实际的Json数据,如下所示:

{"alerts":{"bankAccountInfoNeeded":false,"searchExcludedVehicleIds":[],"unfinishedVehicleId":null},"allowedToAttemptPreApproval":true,"allowedToViewApprovalStatus":false,"bankAccountRequirement":null,"contactInformation":{"city":null,"email":"udannamondaypaul@gmail.com","emailVerified":false,"mobilePhone":null,"mobilePhoneVerified":false,"state":null,"streetAddress":null,"streetAddressLine2":null,"zip":null},"driver":{"allStarHost":false,"firstName":"udanna","id":15227582,"image":{"id":null,"originalImageUrl":"https://resources.turo.com/resources/img/profile/empty-profile_01_large__H7cdab5c9c7828f25764b49b1e54f0b39__.png","placeholder":true,"resizableUrlTemplate":null,"thumbnails":{"84x84":"https://resources.turo.com/resources/img/profile/empty-profile_01_medium__Ha869faa760f43a28da9ca8fbcde22c2d__.png","300x300":"https://resources.turo.com/resources/img/profile/empty-profile_01_large__H7cdab5c9c7828f25764b49b1e54f0b39__.png","225x225":"https://resources.turo.com/resources/img/profile/empty-profile_01_large__H7cdab5c9c7828f25764b49b1e54f0b39__.png","32x32":"https://resources.turo.com/resources/img/profile/empty-profile_01_tiny__H1d3b304549036bd19f7ef997a31d5761__.png"},"verified":false},"lastName":"monday","name":"udanna monday","url":"https://turo.com/drivers/15227582"},"driverLicenseCountryISO3alphaCode":null,"drivingCreditBalance":0.00,"drivingCreditBalanceWithCurency":{"amount":0.00,"currencyCode":"USD"},"drivingCreditBalanceWithCurrency":{"amount":0.00,"currencyCode":"USD"},"eligibleForChatSupport":false,"euNetverifyUser":false,"expertAtManualTransmission":null,"extraCount":0,"hasAdminLink":false,"hasEarnings":false,"hasEnabledVehicles":false,"hasValetLink":false,"imminentReservationIdAsRenter":null,"isEnrolledInOwnerProvidedProtection":false,"isGhosting":false,"isRejectedOrSuspended":true,"latestMobileAppLoginAt":null,"linkedAccounts":{},"loginMethod":"API_PASSWORD","ownerSince":null,"ownerWithApprovedTrips":false,"pendingActionsCount":0,"preferredProtectionLevel":null,"preferredProtectionLevelCountries":[],"shouldDisplayCaliforniaVinRequirementExplanation":false,"shouldResetPassword":false,"trackingId":"ARfxTn92RoSAD8_GEq3bog","turoGoActive":false,"turoGoEligible":false,"unfinishedListingId":null,"upcomingTripCount":0,"vehicleDeliveryLocationCount":0,"vehicles":[]}

但是使用python发出请求时,我得到一个错误json数据

以下是我的python代码:

import json
import requests
s = requests.Session()
url = "https://turo.com/api/login"
datas = {"username":"udannamondaypaul@gmail.com", "password":"udannamondaypaul@gmail.com"}

head = {
"content-type": "multipart/form-data; boundary=----WebKitFormBoundaryMxHFUWBzNpPLcBew",
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"origin": "https://turo.com",
"referer": "https://turo.com/iframes/login/index.html?locale=en_US",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
}

rr = s.post(url, data = json.dumps(datas), headers = head)

现在尝试获取所需的json数据时,我收到了一条错误消息

rr.text
u'{"error":"captcha_token_is_required","errors":[{"additionalDescription":null,"code":"captcha_token_is_required","data":null,"field":null,"message":"Captcha token is required"}],"message":"Captcha token is required"}'

请问如何使用python获取实际的json数据?我很高兴能多帮一把


Tags: 数据httpscomjsonfalseurlimgpng

热门问题