question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot make URL query string with a parameter without a value

See original GitHub issue

URL query string may contain a parameter, which has no value i.e. http://host/path/?foo or http://host/path/?a=1&foo. Currently Requests does not provide support for that.

In [68]: d
Out[68]: {'a': 1, 'foo': None}

In [69]: tl
Out[69]: [('a', 1), ('foo',)]

In [70]: RequestEncodingMixin._encode_params(d)
Out[70]: 'a=1'

In [71]: RequestEncodingMixin._encode_params(tl)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-71-5d4dac855108> in <module>()
----> 1 RequestEncodingMixin._encode_params(tl)

/home/f557010/jpm/local/lib/python2.7/site-packages/requests/models.pyc in _encode_params(data)
     87         elif hasattr(data, '__iter__'):
     88             result = []
---> 89             for k, vs in to_key_val_list(data):
     90                 if isinstance(vs, basestring) or not hasattr(vs, '__iter__'):
     91                     vs = [vs]

ValueError: need more than 1 value to unpack

Expected:

'a=1&foo'

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:4
  • Comments:34 (14 by maintainers)

github_iconTop GitHub Comments

11reactions
kennethreitzcommented, Mar 13, 2018

in 3.0, i think we can consider making emptry string not result in an =

7reactions
agileviccommented, Jul 27, 2015

It’s not the same as having a parameter without a value. Yours renders the = sign after the parameter name. Some applications will work, but as a matter of providing a complete solution this exact case should be addressed. That urllib doesn’t do it is of no significance. Requests does many things better than standard libraries for HTTP - that is its reason to exist.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is a url query parameter valid if it has no value? - Stack Overflow
Although it is recognized that the query string will often carry name-value pairs, it is not required to (e.g. it will often contain...
Read more >
Handling query string parameters with no value in ASP.NET ...
So, let's see what we can do about it! By default, a boolean parameter is bound using SimpleTypeModelBinder , which is used for...
Read more >
URLSearchParams - Web APIs - MDN Web Docs
Chrome Edge URLSearchParams Full support. Chrome49. Toggle history Full support. Edge... @@iterator Full support. Chrome49. Toggle history Full support. Edge... URLSearchParams() constructor Full support. Chrome49. Toggle...
Read more >
URL query string parameters in list and workflow criteria
Query string parameters are added to your website URLs when you use tracking URLs to track a visit from a certain source and...
Read more >
How to Use Query Strings and Parameters for Marketers
While adding multiple values or symbols in your query string, you need to encode them correctly in order for your query string to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found