-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KeyError if parameter is empty #83
Comments
Unless I misunderstand you, this is the expected behavior of furl.args is a dictionary (an orderedmultidict to be specific), and just like a >>> d = {1:1}
>>> d[2]
Traceback (most recent call last):
...
KeyError: 2
>>>
>>> from furl import furl
>>> f = furl('http://www.google.com/?1=1')
>>> dict(f.args)
{'1': '1'}
>>> f.args[2]
Traceback (most recent call last):
...
KeyError: 2 To avoid raising a KeyError on a missing key, use the >>> from furl import furl
>>> f = furl('http://www.google.com/?1=1')
>>> dict(f.args)
{'1': '1'}
>>> print(f.args.get(2))
None Or, in your example import os
uri = os.environ['REQUEST_URI']
from furl import furl
f = furl(uri)
print f.args.get('product')
print f.args.get('category') Does that answer your question? |
Little bump -- does my previous question answer your question, @billdesk? |
Closing due to inactivity. Please reopen if your query was unanswered above. |
import os
uri = os.environ['REQUEST_URI']
from furl import furl
f = furl(uri)
print f.args['product']
print f.args['category']
If current uri is /product.py?product=12&category=2
Then it prints 12 and 2
But if current uri is /product.py?product=12
it throws KeyError
The text was updated successfully, but these errors were encountered: