• 4
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I was curious what the difference was between the data parameter and the params parameter in a python-requests request, and when each should be used.

One example is I have an array of dicts users=[{"email_hash": "fh7834uifre8houi3f"}, ... ] and I try to do a POST (requests.post()) with

params = {
    "ads_token": blah blah,
    "user_id": blah blah,
    "users": json.dumps(users)  # users=[{"email_hash": "fh7834uifre8houi3f"}, ... ]
    "hash_type": "md5"
}

and because users is a few hundred long, the resulting string from json.dumps(users) (and thus the URL itself as well) is very long and I get the error {'status_code': 414, 'reason': 'Request-URI Too Large'}. Would this be a case for data or is there some other path I should follow? Thanks!

params form the query string in the URL, data is used to fill the body of a request (together with files). GET and HEAD requests have no body.

For the majority of servers accepting a POST request, the data is expected to be passed in as the request body.

You need to consult the documentation for the specific API you are calling as to what they expect, but if you have to assume, assume you have to use data.

  • 47
Reply Report
      • 1
    • Awesome, thank you for the quick and concise answer! So the main difference is query string vs. body? And does that mean GET usually uses params, POST usually uses data (and files), and what about DELETE?
      • 1
    • @tscizzle: the point of using a body is to allow for large amounts of data to be transferred; it is rare a DELETE needs to transfer large amounts to get the method actioned on a server. Note that data and params are not mutually exclusive; I've seen URLs that accept POST requests with both query parameters and a body carrying meaning.

Trending Tags