code: def safe_urlencode(params, doseq=0):
      
      if IS_PY3:
          return urlencode(params, doseq)
  
      if hasattr(params, "items"):
          params = params.items()
  
      new_params = []
  
      for k, v in params:
          k = k.encode("utf-8")
  
          if isinstance(v, (list, tuple)):
              new_params.append((k, [force_bytes(i) for i in v]))
          else:
              new_params.append((k, force_bytes(v)))
  
      return urlencode(new_params, doseq)
docs: UTF-8-safe version of safe_urlencode
  
      The stdlib safe_urlencode prior to Python 3.x chokes on UTF-8 values
      which can't fail down to ascii.