我有一个curl请求,使我在终端上收到“ 200”响应,但是当我使用“ https://curl.trillworks.com/”将其转换为python并使用终端发送python请求时,我得到了“ 403”作为响应。
卷曲请求
curl 'https://www.realestate.com.au/agent/graphql' --data-binary $'{"operationName":"SendEnquiry","variables":{"enquiry":{"id":"1375705","enquiryType":"General enquiry","propertyAddress":"","message":"Australia property prices?","contactMethod":"EMAIL","name":"sadfal","phone":"","email":"ahmadarshi@ucp.edu.pk","sourceUrl":"https://www.realestate.com.au/agent/mary-wang-1375705","referrer":""}},"query":"mutation SendEnquiry($enquiry: ConsumerEnquiryInput\u21) {\\n sendEnquiry(enquiry: $enquiry) {\\n status\\n isValid\\n message\\n __typename\\n }\\n}\\n"}' --compressed
Python请求
import requests
data = '${"operationName":"SendEnquiry","variables":{"enquiry":{"id":"1375705","enquiryType":"General enquiry","propertyAddress":"","message":"Australia property prices?","contactMethod":"EMAIL","name":"sadfal","phone":"","email":"ahmadarshi@ucp.edu.pk","sourceUrl":"https://www.realestate.com.au/agent/mary-wang-1375705","referrer":""}},"query":"mutation SendEnquiry($enquiry: ConsumerEnquiryInput\\u21) {\\\\n sendEnquiry(enquiry: $enquiry) {\\\\n status\\\\n isValid\\\\n message\\\\n __typename\\\\n }\\\\n}\\\\n"}'
response = requests.post('https://www.realestate.com.au/agent/graphql', data=data)
答案 0 :(得分:0)
403表示该请求被拒绝(禁止您访问该页面)。请确保您已通过API文档验证了请求所需的标头以及可能需要与数据一起指定的Content-Type
。
另外,看来您可能对请求的格式有误-$
应该从字符串中排除。
答案 1 :(得分:0)
它似乎是https://curl.trillworks.com/ bash解析器中的错误-$不会传递给curl,也不属于要发布的数据的一部分。如果我是你的话,我会向bugllworks的人发送错误报告。引用http://mywiki.wooledge.org/Quotes:
$'...':这是Bash扩展名。它可以防止除反斜杠转义之外的所有操作,还允许特殊的反斜杠转义序列,例如\ n表示换行符,\ t表示制表符,\ xnn表示十六进制指定的字节。
和curl.trillworks.com解析器错误地解析了$'...'语法。