My problem is slightly different from many others. I am doing a POST with a response of a download PDF (not text) and you can see the stack trace below. I can not find any answers on this.
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 Connected to pydev debugger (build 212.5457.59) debug - turned on 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; font-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"> URL: https://homeland.my.salesforce.com/sfc/p/1I000003o0lm/a/8W000001Dmtq/GT9FLcwrLX3QQjVDLCEonLxmCi6nG4VqCUJzDyK80GU Traceback (most recent call last): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 1001, in send self.sock.sendall(data) File "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'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\Quentin_Sarafinchan\PycharmProjects\02_getproperty\venv\lib\site-packages\requests\api.py", line 61, in request return session.request(method=method, url=url, **kwargs) File "C:\Users\Quentin_Sarafinchan\PycharmProjects\02_getproperty\venv\lib\site-packages\requests\sessions.py", line 542, in request resp = self.send(prep, **send_kwargs) File "C:\Users\Quentin_Sarafinchan\PycharmProjects\02_getproperty\venv\lib\site-packages\requests\sessions.py", line 655, in send r = adapter.send(request, **kwargs) File "C:\Users\Quentin_Sarafinchan\PycharmProjects\02_getproperty\venv\lib\site-packages\requests\adapters.py", line 439, in send resp = conn.urlopen( File "C:\Users\Quentin_Sarafinchan\PycharmProjects\02_getproperty\venv\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen httplib_response = self._make_request( File "C:\Users\Quentin_Sarafinchan\PycharmProjects\02_getproperty\venv\lib\site-packages\urllib3\connectionpool.py", line 394, in _make_request conn.request(method, url, **httplib_request_kw) File "C:\Users\Quentin_Sarafinchan\PycharmProjects\02_getproperty\venv\lib\site-packages\urllib3\connection.py", line 239, in request super(HTTPConnection, self).request(method, url, body=body, headers=headers) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 1285, in request self._send_request(method, url, body, headers, encode_chunked) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 1331, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 1280, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 1079, in _send_output self.send(chunk) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\http\client.py", line 1005, in send self.sock.sendall(d) File "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-BaseException