GreyDGL / PentestGPT

A GPT-empowered penetration testing tool
MIT License
7.29k stars 886 forks source link

UnicodeEncodeError #30

Closed Cerisk closed 1 year ago

Cerisk commented 1 year ago

So I have been trying to test the connection using the appropriate python file, but I consistently get the same error:

Traceback (most recent call last): File "/Users/gold/Documents/Programs/PentestGPT/test_connection.py", line 13, in chatgpt = ChatGPT(chatgpt_config) ^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gold/Documents/Programs/PentestGPT/utils/chatgpt.py", line 78, in init self.headers["authorization"] = self.get_authorization() ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gold/Documents/Programs/PentestGPT/utils/chatgpt.py", line 84, in get_authorization r = requests.get(url, headers=self.headers) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/requests/api.py", line 73, in get return request("get", url, params=params, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/requests/api.py", line 59, in request return session.request(method=method, url=url, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/requests/sessions.py", line 587, in request resp = self.send(prep, send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/requests/sessions.py", line 701, in send r = adapter.send(request, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/requests/adapters.py", line 489, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/urllib3/connectionpool.py", line 703, in urlopen httplib_response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/urllib3/connectionpool.py", line 398, in _make_request conn.request(method, url, *httplib_request_kw) File "/opt/homebrew/lib/python3.11/site-packages/urllib3/connection.py", line 244, in request super(HTTPConnection, self).request(method, url, body=body, headers=headers) File "/opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1283, in request self._send_request(method, url, body, headers, encode_chunked) File "/opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1324, in _send_request self.putheader(hdr, value) File "/opt/homebrew/lib/python3.11/site-packages/urllib3/connection.py", line 224, in putheader _HTTPConnection.putheader(self, header, values) File "/opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1256, in putheader values[i] = one_value.encode('latin-1') ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeEncodeError: 'latin-1' codec can't encode character '\u2026' in position 512: ordinal not in range(256)

I am going to inspect, network, filter using the session URL, click headers, and go to request headers. I copied the entire value for cookie and put it as the value for the chatgpt_config.py file and it generates the above error. I wanted to know if this was an issue on my side or if it is a possible error with something that was included?

Cerisk commented 1 year ago

I have been running some tests. Apparently it does work on my home device which uses windows 11 (specifically opera gx as the browser). The device I am running on that is getting this error is a Mac. I uninstalled the version of Python on the Mac and reinstalled the same python version (3.10.9) that my desktop is running but it still gets this error. Anyone getting similar issues on devices that are not using Mac OS?

Edit: Just tested Opera on my Mac and it just the error that I am giving it an incorrectly formatted cookie and to check the readme (used all the different URLs to test it).

GreyDGL commented 1 year ago

I tend to think that encoding error comes from non-standard chars, which should be a language issue. Can you confirm if the browser (Chrome, etc.) is using English as the primary language? Though I don't think cookies will include any non-standard chars..

Cerisk commented 1 year ago

It is indeed using english and from what I looked up that was the same troubleshooting answer I got. It seems strange just because I get this error only on my Mac but not my windows device.

davdu31 commented 1 year ago

I think your error comes from the fact that you did not copy the RAW version of the cookies but just a truncated preview given by the inspector, hence the character \u2026 which corresponds to "..." It depends of the browser

Cerisk commented 1 year ago

I think your error comes from the fact that you did not copy the RAW version of the cookies but just a truncated preview given by the inspector, hence the character \u2026 which corresponds to "..." It depends of the browser

Strange, because when I go through the exact same process on my Windows 11 device, it works. Is it a somewhat different process based on the OS of the device (I would assume its not)?

Cerisk commented 1 year ago

Even more strange, it seems now that it works. I pulled the cookie from "https://chat.openai.com/?model=text-davinci-002-render-sha" and it worked. I guess the recent update you did fixed something or the devs for the website did something to fix it.

GreyDGL commented 1 year ago

I'm not sure lol. But anyway it would be nice to see it works. You can also try the latest OpenAI API supports. This issue can be closed for now.