API does not accept url encoded query strings #1710

Closed
opened 2025-12-29 16:34:38 +01:00 by adam · 1 comment
Owner

Originally created by @wrouesnel on GitHub (Apr 30, 2018).

Issue type

[x] Bug report

Environment

  • Python version: 3.6.5
  • NetBox version: 75465a340476 (v2.3.3)

Description

Try querying a device type using the regular query syntax with a simple URL:
/api/dcim/device-types/?q=&slug=unknown model

Result - it'll work

Try the same query with a properly URL encoded string as produced by requests for example:
/api/dcim/device-types/?q=&slug=unknown%20model

Result - no results. A totally different query.

To make this query work I have to intentionally send malformed requests to the endpoint when using requests:

greq = requests.Request(method='GET', url=netbox_uri + '/api/dcim/device-types/')
prep = greq.prepare()
prep.url = netbox_uri + '/api/dcim/device-types/' + '?q=&slug={}'.format('unknown model')
r = s.send(prep)

Which is obviously far from ideal.

Originally created by @wrouesnel on GitHub (Apr 30, 2018). ### Issue type [x] Bug report <!-- Unexpected or erroneous behavior --> <!-- Please describe the environment in which you are running NetBox. (Be sure to verify that you are running the latest stable release of NetBox before submitting a bug report.) If you are submitting a bug report and have made any changes to the code base, please first validate that your bug can be recreated while running an official release. --> ### Environment * Python version: 3.6.5 * NetBox version: 75465a340476 (v2.3.3) <!-- BUG REPORTS must include: * A list of the steps needed for someone else to reproduce the bug * A description of the expected and observed behavior * Any relevant error messages (screenshots may also help) FEATURE REQUESTS must include: * A detailed description of the proposed functionality * A use case for the new feature * A rough description of any necessary changes to the database schema * Any relevant third-party libraries which would be needed --> ### Description Try querying a device type using the regular query syntax with a simple URL: `/api/dcim/device-types/?q=&slug=unknown model` Result - it'll work Try the same query with a properly URL encoded string as produced by requests for example: `/api/dcim/device-types/?q=&slug=unknown%20model` Result - no results. A totally different query. To make this query work I have to intentionally send malformed requests to the endpoint when using requests: ``` greq = requests.Request(method='GET', url=netbox_uri + '/api/dcim/device-types/') prep = greq.prepare() prep.url = netbox_uri + '/api/dcim/device-types/' + '?q=&slug={}'.format('unknown model') r = s.send(prep) ``` Which is obviously far from ideal.
adam closed this issue 2025-12-29 16:34:38 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jul 5, 2018):

Slugs generally use hyphens instead of spaces to avoid this problem. That said, NetBox relies on django-filter for query filtering, so any requests for changes to this behavior would need to be submitted against that project.

@jeremystretch commented on GitHub (Jul 5, 2018): Slugs generally use hyphens instead of spaces to avoid this problem. That said, NetBox relies on [django-filter](https://github.com/carltongibson/django-filter) for query filtering, so any requests for changes to this behavior would need to be submitted against that project.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1710