title: Using python's urllib.quote_plus on utf-8 strings with 'safe' arguments
body: <p>I have a unicode string in python code:</p>
  
  <pre><code>name = u'Mayte_Martín'
  </code></pre>
  
  <p>I would like to use it with a SPARQL query, which meant that I should encode the string using 'utf-8' and use urllib.quote_plus or requests.quote on it. However, both these quote functions behave strangely as can be seen when used with and without the 'safe' arguments.</p>
  
  <pre><code>from urllib import quote_plus
  </code></pre>
  
  <p>Without 'safe' argument:</p>
  
  <pre><code>quote_plus(name.encode('utf-8'))
  Output: 'Mayte_Mart%C3%ADn'
  </code></pre>
  
  <p>With 'safe' argument:</p>
  
  <pre><code>quote_plus(name.encode('utf-8'), safe=':/')
  Output: 
  ---------------------------------------------------------------------------
  UnicodeDecodeError                        Traceback (most recent call last)
  &lt;ipython-input-164-556248391ee1&gt; in &lt;module&gt;()
  ----&gt; 1 quote_plus(v, safe=':/')
  
  /usr/lib/python2.7/urllib.pyc in quote_plus(s, safe)
     1273         s = quote(s, safe + ' ')
     1274         return s.replace(' ', '+')
  -&gt; 1275     return quote(s, safe)
     1276 
     1277 def urlencode(query, doseq=0):
  
  /usr/lib/python2.7/urllib.pyc in quote(s, safe)
     1264         safe = always_safe + safe
     1265         _safe_quoters[cachekey] = (quoter, safe)
  -&gt; 1266     if not s.rstrip(safe):
     1267         return s
     1268     return ''.join(map(quoter, s))
  
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128)
  </code></pre>
  
  <p>The problem seems to be with rstrip function. I tried to make some changes and call as...</p>
  
  <pre><code>quote_plus(name.encode('utf-8'), safe=u':/'.encode('utf-8'))
  </code></pre>
  
  <p>But that did not solve the issue. What could be the issue here?</p>