MahdiFarnaghi / intelli_geo

IntelliGeo is QGIS plugin that facilitates interaction with Large Language Models in QGIS environment.
Apache License 2.0
1 stars 0 forks source link

Problem with encoding in Czech Localization #11

Open Krasnystehno opened 1 week ago

Krasnystehno commented 1 week ago

Describe the bug When inputting API key, after confirming everything an error shows that reads this: UnicodeEncodeError: 'latin-1' codec can't encode character '\u0159' in position 11: ordinal not in range(256) Traceback (most recent call last): File ".../QGIS3\profiles\default/python/plugins\intelli_geo\intelli_geo.py", line 295, in onNewMessageSend self.onConversationNewed() File ".../QGIS3\profiles\default/python/plugins\intelli_geo\intelli_geo.py", line 346, in onConversationNewed self.dataloader.createConversation(metaInfo) File ".../QGIS3\profiles\default/python/plugins\intelli_geo\dataloader.py", line 363, in createConversation self.insertConversationInfo(metaInfo) File ".../QGIS3\profiles\default/python/plugins\intelli_geo\dataloader.py", line 245, in insertConversationInfo self.postData("conversation", conversationInfoDict) File ".../QGIS3\profiles\default/python/plugins\intelli_geo\dataloader.py", line 411, in postData response = requests.post(f"{self.backendURL}/{endpoint}", json=dataDict, headers=header) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "...\apps\Python312\Lib\site-packages\requests\api.py", line 115, in post return request("post", url, data=data, json=json, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "...\apps\Python312\Lib\site-packages\requests\api.py", line 59, in request return session.request(method=method, url=url, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "...\apps\Python312\Lib\site-packages\requests\sessions.py", line 589, in request resp = self.send(prep, send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "...\apps\Python312\Lib\site-packages\requests\sessions.py", line 703, in send r = adapter.send(request, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "...\apps\Python312\Lib\site-packages\requests\adapters.py", line 486, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "...\apps\Python312\Lib\site-packages\urllib3\connectionpool.py", line 793, in urlopen response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "...\apps\Python312\Lib\site-packages\urllib3\connectionpool.py", line 496, in _make_request conn.request( File "...\apps\Python312\Lib\site-packages\urllib3\connection.py", line 399, in request self.putheader(header, value) File "...\apps\Python312\Lib\site-packages\urllib3\connection.py", line 313, in putheader super().putheader(header, *values) File "...\apps\Python312\Lib\http\client.py", line 1309, in putheader values[i] = one_value.encode('latin-1') ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeEncodeError: 'latin-1' codec can't encode character '\u0159' in position 11: ordinal not in range(256)

To Reproduce

  1. Use a computer with Czech Republic Localization (Windows 11)
  2. Install the plugin
  3. Type in Hello in the plugin
  4. After popup window shows, add API key and set everything
  5. Klick OK on the dialog window
  6. This error will show

Expected behavior The plugin should work normally with no errors.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context I have the same problem with GRASS in QGIS

com3dian commented 6 days ago

Hi @Krasnystehno,

Thank you for raising this issue. I'm currently investigating it, but since I'm not in the Czech Republic, it's difficult for me to reproduce the exact error. From what I can tell, the issue seems to be related to Czech characters in your macID or Ethernet interface names.

If you'd like to try solving this issue, I recommend following these steps. While I can't guarantee this will completely fix the problem, it's likely to help:

  1. Open QGIS, then click on Settings -> User Profiles -> Open Active Profile Folder. Screenshot from 2024-09-13 10-06-08 This will open the user folder. If there is a folder named python, open it, then navigate to python -> plugins -> intelli_geo. You should now be in the source code folder.

  2. Open the utils.py file using an editor like Notepad or VS Code. Find line 192, and paste the following function:

    def cleanLatin1String(inputString):
        # Encode to latin-1 and decode to handle non-latin-1 characters
        return inputString.encode('latin-1', 'replace').decode('latin-1')
  3. Find the following lines: https://github.com/MahdiFarnaghi/intelli_geo/blob/c5c04454a5ec791aca2208a0bceaf683113a399e/utils.py#L208-L212 and replace them with this:

        systemInfo = {
            "macID": cleanLatin1String(macAddresses[0]) if macAddresses else "N/A",
            "ethInterfaces": cleanLatin1String(', '.join(ethInterfaces)),
            "qgisVersion": qgisVersion
        }
  4. Restart QGIS, remove any existing conversations, and create a new one.

Please note that we have deactivated the API key provided during the workshop. If you have an OpenAI API key, you can use that, or you can generate a free API key from Cohere.