查看python中的发布请求

时间:2020-04-28 19:52:06

标签: python python-requests

我正在尝试编写python脚本以从以下页面获取“我的个人资料”数据:https://turo.com/us/en/login 在Firefox中使用f12,我获得了标头,请求有效载荷,请求有效载荷的表单数据(请求主体)。

这是我的电子邮件地址和密码以及主要的api网址:

密码:udannamondaypaul@gmail.com

用户名:udannamondaypaul@gmail.com

发布请求的API网址: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数据?我会为此加倍高兴。

0 个答案:

没有答案