Skip to content

If data is dictionary send it as form data #19

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

Merged
merged 4 commits into from
Feb 24, 2020
Merged

Conversation

FoamyGuy
Copy link
Contributor

In python3 with requests we can use code like this:

import requests
URL = "https://docs.google.com/forms/u/0/d/e/1FAIpQLScoUhFA1BIJjXF2-QM_mxNMN62Y2BCJ--gwJIwWcwJPvWDlwQ/formResponse"
form_data = {
    "entry.2004206042": "Hello",
    "entry.487209416": "Binka"
}
r = requests.post(URL, data=form_data)
print(r.text)

And the data will get sent as form data. More specifically using the format:
name=value&other_name=other_value

and gets sent using Content-Type: application/x-www-form-urlencoded

This allows us to use a simple dictionary for our form data but submit it to web apps expecting data from an html <form> element.

This change allows the circuitpython requests library to behave similarly. When data is a dictionary it will get formatted into the key/value string and sent with Content-Type: application/x-www-form-urlencoded

With this change we can use almost the same code for python3 and CircuitPython to post data to Google forms/spreadsheets and and similar <form> based web apps.

@FoamyGuy FoamyGuy requested a review from a team February 22, 2020 17:18
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thank you.

@tannewt tannewt merged commit e8a7597 into adafruit:master Feb 24, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Feb 25, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_Heart_Rate to 1.0.1 from 1.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE_Heart_Rate#4 from dhalbert/packet-size

Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 1.2.0 from 1.1.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_Requests#19 from FoamyGuy/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_HTS221
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants