Curl和Requests产生不同的输出

时间:2017-06-26 00:48:48

标签: python curl python-requests

卷曲:

curl 'https://www.bcauction.ca/open.dll/submitDocumentApproval?isbid=Y' -H 'Cookie: secure, HttpOnly; secure, HttpOnly; sessionID=|2062440311||768320184|' -H 'Origin: https://www.bcauction.ca' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-CA,en;q=0.8,ja;q=0.6' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36' -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryXaM3hkXUh3p92ki8' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: https://www.bcauction.ca/open.dll/showBidConfirmation?sessionID=768320184&Language=En&disID=7322551&dis_version_nos=&docType=Tender&docTypeQual=TN' -H 'Connection: keep-alive' -H 'DNT: 1' --data-binary $'------WebKitFormBoundaryXaM3hkXUh3p92ki8\r\nContent-Disposition: form-data; name="disID"\r\n\r\n7322551\r\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\r\nContent-Disposition: form-data; name="docType"\r\n\r\nTender\r\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\r\nContent-Disposition: form-data; name="docTypeQual"\r\n\r\nTN\r\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\r\nContent-Disposition: form-data; name="docCheckAllow"\r\n\r\n\r\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\r\nContent-Disposition: form-data; name="poptID"\r\n\r\n\r\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\r\nContent-Disposition: form-data; name="IssuedBy"\r\n\r\n\r\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\r\nContent-Disposition: form-data; name="IssuedFor"\r\n\r\n\r\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\r\nContent-Disposition: form-data; name="disReferId"\r\n\r\n\r\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\r\nContent-Disposition: form-data; name="BidAmount"\r\n\r\n4.88\r\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\r\nContent-Disposition: form-data; name="MinimumBid"\r\n\r\n4.880\r\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\r\nContent-Disposition: form-data; name="dllPage"\r\n\r\nbid_confirmation.html\r\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\r\nContent-Disposition: form-data; name="dllAnchor_pageLevel"\r\n\r\npageLevel\r\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\r\nContent-Disposition: form-data; name="sessionID"\r\n\r\n768320184\r\n------WebKitFormBoundaryXaM3hkXUh3p92ki8--\r\n' --compressed

输出:

<head><title>Document Moved</title></head>
<body><h1>Object Moved</h1>This document may be found <a HREF="showErrorDisplay?sessionID=768320184&amp;errorMessage=ValErr0000||&lt;b&gt;Sorry, you have been OUTBID, click on Close to refresh the auction and bid again&lt;/b&gt;.&amp;ReloadOpener=Y&amp;messageType=Informational">here</a ></body>


请求:

import requests

cookies = {
    'sessionID': '|2062440311||768320184|',
}

headers = {
    'Origin': 'https://www.bcauction.ca',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'en-CA,en;q=0.8,ja;q=0.6',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
    'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryXaM3hkXUh3p92ki8',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Cache-Control': 'max-age=0',
    'Referer': 'https://www.bcauction.ca/open.dll/showBidConfirmation?sessionID=768320184&Language=En&disID=7322551&dis_version_nos=&docType=Tender&docTypeQual=TN',
    'Connection': 'keep-alive',
    'DNT': '1',
}

params = (
    ('isbid', 'Y'),
)

data = '$------WebKitFormBoundaryXaM3hkXUh3p92ki8\\r\\nContent-Disposition: form-data; name="disID"\\r\\n\\r\\n7322551\\r\\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\\r\\nContent-Disposition: form-data; name="docType"\\r\\n\\r\\nTender\\r\\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\\r\\nContent-Disposition: form-data; name="docTypeQual"\\r\\n\\r\\nTN\\r\\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\\r\\nContent-Disposition: form-data; name="docCheckAllow"\\r\\n\\r\\n\\r\\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\\r\\nContent-Disposition: form-data; name="poptID"\\r\\n\\r\\n\\r\\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\\r\\nContent-Disposition: form-data; name="IssuedBy"\\r\\n\\r\\n\\r\\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\\r\\nContent-Disposition: form-data; name="IssuedFor"\\r\\n\\r\\n\\r\\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\\r\\nContent-Disposition: form-data; name="disReferId"\\r\\n\\r\\n\\r\\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\\r\\nContent-Disposition: form-data; name="BidAmount"\\r\\n\\r\\n5.50\\r\\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\\r\\nContent-Disposition: form-data; name="MinimumBid"\\r\\n\\r\\n5.50\\r\\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\\r\\nContent-Disposition: form-data; name="dllPage"\\r\\n\\r\\nbid_confirmation.html\\r\\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\\r\\nContent-Disposition: form-data; name="dllAnchor_pageLevel"\\r\\n\\r\\npageLevel\\r\\n------WebKitFormBoundaryXaM3hkXUh3p92ki8\\r\\nContent-Disposition: form-data; name="sessionID"\\r\\n\\r\\n768320184\\r\\n------WebKitFormBoundaryXaM3hkXUh3p92ki8--\\r\\n'

res = requests.post'https://www.bcauction.ca/open.dll/submitDocumentApproval', headers=headers, params=params, cookies=cookies, data=data)
print(res.text)

输出:

The page cannot be displayed because an internal server error has occurred.

curl和造成差异的请求有什么区别?所有表单数据和标题都是相同的。

1 个答案:

答案 0 :(得分:0)

这是表格数据开头的美元符号。不确定混合的位置。