code: def update_url(url, params):
      
      if not isinstance(url, bytes):
          url = url.encode('utf-8')
      for key, value in list(params.items()):
          if not isinstance(key, bytes):
              del params[key]
              key = key.encode('utf-8')
          if not isinstance(value, bytes):
              value = value.encode('utf-8')
          params[key] = value
      url_parts = list(urlparse(url))
      query = dict(parse_qsl(url_parts[4]))
      query.update(params)
      # make the params order deterministic
      query = list(query.items())
      query.sort()
      url_query = urlencode(query)
      if not isinstance(url_query, bytes):  # pragma: no cover in python3 urlencode return an unicode
          url_query = url_query.encode("utf-8")
      url_parts[4] = url_query
      return urlunparse(url_parts).decode('utf-8')
docs: update parameters using ``params`` in the ``url`` query string
  
          :param url: An URL possibily with a querystring
          :type url: :obj:`unicode` or :obj:`str`
          :param dict params: A dictionary of parameters for updating the url querystring
          :return: The URL with an updated querystring
          :rtype: unicode