← index #6310Issue #6649
Off-topic · high · value 0.085
QUERY · ISSUE

how to use urequests to post files?

openby thugbobbyopened 2020-08-05updated 2024-08-27

I want to post some files to remote server.But I found that the urequests.post() doesn`t have parameter files.

this is in python:

import requests

payload = {}
files = [
  ('uploads2', open('/D:/cat.png','rb')),
  ('uploads1', open('/D:/tecsun/456.jpg','rb'))
]
headers= {}

response = requests.request("POST", url, headers=headers, data = payload, files = files)

print(response.text.encode('utf8'))

how to use this in micropython? thank you !

CANDIDATE · ISSUE

POST Request with BASIC AUTH - How to?

closedby tongclementopened 2020-11-25updated 2024-09-13

Dear all,

I am trying to implement a simple pull request with basic auth on the esp32. As seen at https://github.com/micropython/micropython-lib/pull/311, it seems like it is implemented in urequests.post and can be called by: res = urequests.post(request_url, headers={'content-type': 'application/json'}, data=post_data, auth=('username','password')).json() print(res.text).

However it seems like this doesn't work. Am I not calling this function right? There seems to be no documentation on requests in the official documentation.

Sincerely with Many Thanks,
Clement

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