← index #978Issue #273
Related · high · value 3.256
QUERY · ISSUE

GET param problem

openby shdmfireopened 2025-02-25updated 2025-11-22
needs-info

The GET request in the request library cannot add parameters, and the url constructed to www.xxx.com?token=xxx cannot take effect (this can be recognized normally in the requests library)

2 comments
jonnor · 2025-11-09

Can you provide code to reproduce this issue?

shdmfire · 2025-11-22

url = http://www.xxx.com
path = '/xxx/xxx'
token = 'xxx'
param = f'?token={token}'
url = url + path + param

response = request.request(method=method, url=url, headers=headers, data=body)

CANDIDATE · ISSUE

Request: params keyword argument for urequests

closedby stroobandtopened 2018-04-12updated 2024-08-27

Currently, urequests does not support the params keyword of the original Python requests module.

However, there exists a better urequests implementation which does.
It would be great if that implementation would be adopted.

4 comments
SpotlightKid · 2018-08-26

micropython-lib already contains everything you need to achieve the same:

import urequests
from urllib.parse import urlencode


def get(url, params=None, **kw):
    if params:
        url = url.rstrip('?') + '?' + urlencode(params, doseq=True)
    return urequests.get(url, **kw)


payload = {'key1': 'value1', 'key2': ['value2', 'value3']}
res = get('http://httpbin.org/get', payload)
print(res.json())

Output:

{'url': 'http://httpbin.org/get?key2=value2&key2=value3&key1=value1',
 'headers': {'Host': 'httpbin.org', 'Connection': 'close'},
 'args': {'key2': ['value2', 'value3'], 'key1': 'value1'}, 'origin': 'XX.XXX.XXX.XXX'}
oxygene · 2021-07-10

I'm just doing my first steps in esp32 programming with micropython, so please excuse if I miss something.
I wanted to use urequests to POST some data that uses application/x-www-form-urlencoded. So I need to urlencode my parameters. I can't seem to get it working, though. Installing urllib.parse via upip seems to work initially, but trying to actually import it in the python file results in

>>> from urllib.parse import urlencode
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/urllib/parse.py", line 30, in <module>
  File "/lib/re.py", line 11, in <module>
AttributeError: 'NoneType' object has no attribute 'func'

Any other way to get urlencode working or do I need to implement it myself?

SpotlightKid · 2021-07-10

I created a cut-down version of urlencode for my mrequests module:

https://github.com/SpotlightKid/mrequests/blob/25eac2977f75699985ab735a257c2b8ba9a7a2aa/urlencode.py

Here's a usage example:

https://github.com/SpotlightKid/mrequests/blob/25eac2977f75699985ab735a257c2b8ba9a7a2aa/examples/formencode.py

jonnor · 2024-08-25

Several workaround are available here. Proposing to close this issue.

If someone wants to open a merge request that would also still be welcomed :)

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied