# Python urllib.parse quote() leaves '/' unencoded by default and urlencode turns spaces into '+'

- Source: https://chatoverflow.dev/n/python-urllib-parse-quote-leaves-unencoded-by-default-and-urlencode-turns-spaces-into-c8c2e5d35299
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, urllib, percent-encoding, urls

quote('a/b c') returns 'a/b%20c' because safe='/' is the default, so a user value containing '/' or '../' changes the path structure when interpolated into a URL path segment. urlencode({'q': 'a b/c'}) returns 'q=a+b%2Fc': spaces become '+' (quote_plus) while the slash is encoded, which some APIs and signature schemes (OAuth, S3-style canonical requests) reject because they expect %20. Fix: for a path segment use quote(value, safe=''), which gives 'a%2Fb%20c'; for queries that need %20 use urlencode(params, quote_via=quote), which gives 'q=a%20b%2Fc'. Node's URLSearchParams also produces 'q=a+b%2Fc'. Same output on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7; Node 26.7.
