我的問題與許多其他問題略有不同。我正在使用下載 PDF(不是文本)的回應進行 POST,您可以在下面看到堆疊跟蹤。我找不到任何答案。
base_url = "https://homeland.my.salesforce.com"
action = base_url "/sfc/p/#1I000003o0lm/a/8W000001Dmtq/GT9FLcwrLX3QQjVDLCEonLxmCi6nG4VqCUJzDyK80GU"
qdata = {"compositePageName",
"1I000003o0lm/a/8W000001Dmtq/GT9FLcwrLX3QQjVDLCEonLxmCi6nG4VqCUJzDyK80GU" }
#req = requests.post(url=action, data=qdata)
req = requests.post(url=action, stream=True, data=qdata)
# blows up on above method with message
C:\Users\Quentin_Sarafinchan\PycharmProjects\02_getproperty\venv\Scripts\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.3\plugins\python-ce\helpers\pydev\pydevd.py" -- multiproc --qt-support=auto --client 127.0.0.1 --port 50548 --file C:/Users/Quentin_Sarafinchan/PycharmProjects/02_getproperty/main.py index.html --debug 連接到pydev除錯器(build 212.5457.59) ) 除錯 - 打開 https://homeland.my.salesforce.com/sfc/p/1I000003o0lm/a/8W000001Dmtq/GT9FLcwrLX3QQjVDLCEonLxmCi6nG4VqCUJzDyK80GU" style="mso-style-priority:100 !important;text-decoration:none;-webkit-text-size-adjust:none;-ms-text-size-adjust:none; mso-line-height-rule:exactly ;color:#FFFFFF;font-size:14px;border-style:solid;border-color:#BB9A65;border-width:10px 15px;display:inline-block;background:#BB9A65;border-radius:0px;字體-family:'open sans', 'helvetica neue', helvetica, arial, sans-serif;font-weight:bold;font-style:normal;line-height:17px;width:auto text-align:center" target= "_blank"> 網址:https : //homeland.my.salesforce.com/sfc/p/1I000003o0lm/a/8W000001Dmtq/GT9FLcwrLX3QQjVDLCEonLxmCi6nG4VqCUJzDyK80GU 回溯(最近一次呼叫):檔案“C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\http\client.py”,第 1001 行,發送 self.sock.sendall(data ) 檔案 "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\ssl.py",第 1201 行,在 sendall 中,以 memoryview(data) 作為視圖,view.cast("B") as byte_view: TypeError: memoryview: a bytes-like object is required, not 'str'
在處理上述例外的程序中,又發生了一個例外:
回溯(最近一次呼叫):檔案“C:\Users\Quentin_Sarafinchan\PycharmProjects\02_getproperty\venv\lib\site-packages\requests\api.py”,第 61 行,請求回傳 session.request(method=method, url=url, **kwargs) 檔案“C:\Users\Quentin_Sarafinchan\PycharmProjects\02_getproperty\venv\lib\site-packages\requests\sessions.py”,第 542 行,請求 resp = self.send(prep, * *send_kwargs) 檔案“C:\Users\Quentin_Sarafinchan\PycharmProjects\02_getproperty\venv\lib\site-packages\requests\sessions.py”,第 655 行,發送 r = adapter.send(request, **kwargs) 檔案“ C:\Users\Quentin_Sarafinchan\PycharmProjects\02_getproperty\venv\lib\site-packages\requests\adapters.py”,第 439 行,發送 resp = conn.urlopen( File "C:\Users\Quentin_Sarafinchan\PycharmProjects\02_getproperty\venv\lib\site-packages\urllib3\connectionpool.py”,第 699 行,在 urlopen httplib_response = self._make_request( 檔案“C:\Users\Quentin_Sarafinchan\Pycharmgetpropers\02v lib\site-packages\urllib3\connectionpool.py”,第 394 行,在 _make_request conn.request(method, url, **httplib_request_kw) 檔案“C:\Users\Quentin_Sarafinchan\PycharmProjects\02_getproperty\venv\lib\site-packages \urllib3\connection.py”,第 239 行,在請求 super(HTTPConnection, self).request(method, url, body=body, headers=headers) 檔案“C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3”中.9.2544.0_x64__qbz5n2kfra8p0\lib\http\client.py”,第 1285 行,在請求 self._send_request(method, url, body, headers, encode_chunked) 檔案“C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\http\client.py",第 1331 行,在 _send_request self.endheaders(body, encode_chunked=encode_chunked) File\WindowsApps Files \PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\http\client.py”,第 1280 行,在endheaders self._send_output(message_body, encode_chunked=encode_chunked) 檔案“C:\Program Files.SoftwarePythonApps.PythonApps 3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\http\client.py”,第 1079 行,在 _send_output self.send(chunk) 檔案“C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2564\xfram_bfra8k8.256443.9.256440000000000000000” http\client.py”,第 1005 行,在發送 self.sock.sendall(d) 檔案“C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544”中。0_x64__qbz5n2kfra8p0\lib\ssl.py", line 1201, in sendall with memoryview(data) as view, view.cast("B") as byte_view: TypeError: memoryview: a bytes-like object is required, not 'str' python -基礎例外
uj5u.com熱心網友回復:
需要使用位元組陣列
#qdata = {"compositePageName",
# "1I00EonLxmCi6nG4VqCUJzDyK80GU" }
nm = "compositePageName"
val = "LxmCi6nG4VqCUJzDyK80GU"
s = nm "=" val
qdata = bytearray(s, 'utf-8')
mv = memoryview(qdata)
req = requests.post(url=action, stream=True, data=mv)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/374197.html
