UnicodeEncodeError in Python application

Tobias Genannt tobias.genannt at kappa-velorum.net
Wed Dec 21 20:40:59 UTC 2022


Hi Andrew,

thanks for the instructions those tests. I managed to run the build of 
Unit directly in the container image I'm using. After I reverted the 
commit 491d0f70 and started the newly build Unit the application loaded 
without problems.

Greetings
Tobias

On 21/12/2022 15:41, Andrew Clayton wrote:
> On Fri, 16 Dec 2022 13:28:24 +0100
> Tobias Genannt <tobias.genannt at kappa-velorum.net> wrote:
> 
>> Hello,
> 
> Hi!,
> 
>> I'm seeing a crash in a Python application with Unit 1.29 which is not
>> happening in Unit 1.28. I'm not sure if I have to change the
>> configuration for this version bump because I didn't find an entry in
> 
> No, you shouldn't.
> 
>> the changelog which would point to the problem.
>> This is the stack trace:
> 
> [...]
> 
>>       print(f"\U0001f9ec loaded config '{path}'")
>> UnicodeEncodeError: 'ascii' codec can't encode character '\U0001f9ec' in
>> position 0: ordinal not in range(128)
> 
> OK, so looks like a unicode issue.
>   
>> You can find the contents of the problematic file (last strack trace
>> entry) here:
>> https://github.com/tobiasge/netbox-docker/blob/new-unit/docker/configuration.docker.py
> 
> I did quickly try reproducing this using current unit master and Python
> 3.11
> 
> {
>      "listeners": {
>          "[::1]:8080": {
>              "pass": "applications/python"
>          }
>      },
> 
>      "applications": {
>          "python": {
>              "type": "python",
>              "path": "/srv/unit/python/app/",
>              "module": "app"
>          }
>      }
> }
> 
> $ cat /srv/unit/python/app/app.py
> def application(environ, start_response):
>      start_response("200 OK", [("Content-Type", "text/plain")])
>      print("⚠️ test\n");
>      return (b"Hello, Python on Unit!\n")
> 
> which works OK.
> 
> There aren't that many Python changes since 1.28.0
> 
> $ git log --oneline 1.28.0.. src/python/
> 6dae517e Python: Added "prefix" to configuration.
> 491d0f70 Python: Added support for Python 3.11.
> 6902cd14 Refactored functions that set WSGI variables.
> 3b970ed9 Removed dead code.
> 40d75c94 Optimization for the "--no-unix-sockets" case.
> b0098336 Renamed a couple of members of nxt_unit_request_t.
> 
> If you're up for it, could you try reverting 491d0f70 ("Python: Added
> support for Python 3.11.")?
> 
> $ git clone https://github.com/nginx/unit.git
> $ cd unit
> 
> $ git revert -n 491d0f70
> 
> (ignore the warnings...)
> 
> build unit and the python module etc and test.
> 
> If things are still broken
> 
> $ git reset --hard
> $ git revert -n 6902cd14
> 
> build/install and test again.
> 
> If things are still broken, you could repeat the above with the other
> commits.
> 
> Alternatively, if you have a simple bare minimum reproducer...
> 
>> Greetings,
>> Tobias
> 
> Cheers,
> Andrew


More information about the unit mailing list