Webhooks UTF-8 trouble #3618

Closed
opened 2025-12-29 18:30:12 +01:00 by adam · 1 comment
Owner

Originally created by @proudbro on GitHub (Apr 28, 2020).

Originally assigned to: @kobayashi on GitHub.

Environment

  • Python version: 3.6.9
  • NetBox version: 2.8.1

Steps to Reproduce

  1. Disable any installed plugins by commenting out the PLUGINS setting in
    configuration.py.
  2. Create webhook
    Object Type: Tenant
    HTTP content type: application/json
    HTTP method: POST
    Additional headers: No Additional Headers
    Body template: {"text": " [{{model}}] Name:{{data['name']}}, ID:{{data['id']}} was {{event}} by {{username}}"}
  3. Create a Tenant object with Cyrillic Symbols in NAME field

Expected Behavior

Successfully get a webhook as we received before with latin symbols

Observed Behavior

Go into Failed Jobs in Admin panel and see Exception in job info:

Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/rq/worker.py", line 884, in perform_job
rv = job.perform()
File "/usr/local/lib/python3.6/dist-packages/rq/job.py", line 664, in perform
self._result = self._execute()
File "/usr/local/lib/python3.6/dist-packages/rq/job.py", line 670, in _execute
return self.func(*self.args, **self.kwargs)
File "/opt/netbox/netbox/extras/webhooks_worker.py", line 72, in process_webhook
response = session.send(prepared_request)
File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 672, in urlopen
chunked=chunked,
File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 387, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.6/http/client.py", line 1264, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1309, in _send_request
body = _encode(body, 'body')
File "/usr/lib/python3.6/http/client.py", line 171, in _encode
(name.title(), data[err.start:err.end], name)) from None
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 25-28: Body ('ТЕСТ') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

Originally created by @proudbro on GitHub (Apr 28, 2020). Originally assigned to: @kobayashi on GitHub. <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report, and that any plugins have been disabled. --> ### Environment * Python version: 3.6.9 * NetBox version: 2.8.1 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> ### Steps to Reproduce 1. Disable any installed plugins by commenting out the `PLUGINS` setting in `configuration.py`. 2. Create webhook Object Type: Tenant HTTP content type: application/json HTTP method: POST Additional headers: _No Additional Headers_ Body template: `{"text": " [{{model}}] Name:{{data['name']}}, ID:{{data['id']}} was {{event}} by {{username}}"}` 3. Create a Tenant object with Cyrillic Symbols in NAME field <!-- What did you expect to happen? --> ### Expected Behavior Successfully get a webhook as we received before with latin symbols <!-- What happened instead? --> ### Observed Behavior Go into Failed Jobs in Admin panel and see Exception in job info: > Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/rq/worker.py", line 884, in perform_job rv = job.perform() File "/usr/local/lib/python3.6/dist-packages/rq/job.py", line 664, in perform self._result = self._execute() File "/usr/local/lib/python3.6/dist-packages/rq/job.py", line 670, in _execute return self.func(*self.args, **self.kwargs) File "/opt/netbox/netbox/extras/webhooks_worker.py", line 72, in process_webhook response = session.send(prepared_request) File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 643, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.6/dist-packages/requests/adapters.py", line 449, in send timeout=timeout File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 672, in urlopen chunked=chunked, File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 387, in _make_request conn.request(method, url, **httplib_request_kw) File "/usr/lib/python3.6/http/client.py", line 1264, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/lib/python3.6/http/client.py", line 1309, in _send_request body = _encode(body, 'body') File "/usr/lib/python3.6/http/client.py", line 171, in _encode (name.title(), data[err.start:err.end], name)) from None UnicodeEncodeError: 'latin-1' codec can't encode characters in position 25-28: Body ('ТЕСТ') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.
adam added the type: bugstatus: accepted labels 2025-12-29 18:30:12 +01:00
adam closed this issue 2025-12-29 18:30:12 +01:00
Author
Owner

@kobayashi commented on GitHub (Apr 29, 2020):

I can reproduce this issue.
Similar issue was opened in https://github.com/psf/requests/issues/1822

@kobayashi commented on GitHub (Apr 29, 2020): I can reproduce this issue. Similar issue was opened in https://github.com/psf/requests/issues/1822
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3618