The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Get A Web Page Via A Post Request In Python

TODO: Pull subtitle into page object

This is an example of how to use the Python `requests` module to send a POST request to a web server that includes headers and a json payload. (The specific example is for a meilisearch server in this case.)

NOTE: I'm pretty sure you need to install `requests` with `pip` or `pip3`. For example:

code_start_default_section code_end_default_section

Note: the results have been locked in so the bearer token can be removed. The code has been set to :eval never to prevent accidentally running it.

#+NAME: listing-1 #+begin_src python :post results_padder(data=*this*) :results output :wrap example :eval never

import requests

url = 'http://127.0.0.1:7700/indexes/grimoire/search'

headers = { 'Authorization': 'Bearer aaaaabbbbbccccccddddddd', 'Content-Type': 'application/json' }

data = { 'q': 'example' }

response = requests.post(url, headers=headers, json=data)

print(f'Status: {response.status_code}') print(f'Returned: {response.json()}')

#+end_src

Results
Status: 200
  
  Returned:
  {
    "hits": [
      {
        "id": "100",
        "filename": "Example State Names",
      }
    ]
  }

TODO: Link up other version of getting pages via GET

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Get A Web Page Via A Post Request In Python

-- p

This is an example of how to use the Python
`requests` module to send a POST request to
a web server that includes headers and
a json payload. (The specific example is
for a meilisearch server in this case.)

-- p

NOTE: I'm pretty sure you need to install
`requests` with `pip` or `pip3`. For
example:

-- code/
-- bash

pip install requests

-- /code

-- p

Note: the results have been locked in so the
  bearer token can be removed. The code has
  been set to :eval never to prevent accidentally
  running it.

-- p

#+NAME: listing-1
#+begin_src python :post results_padder(data=*this*) :results output :wrap example :eval never

-- p

import requests

-- p

url = 'http://127.0.0.1:7700/indexes/grimoire/search'

-- p

headers = {
      'Authorization': 'Bearer aaaaabbbbbccccccddddddd',
      'Content-Type': 'application/json'
      }

-- p

data = {
      'q': 'example'
      }

-- p

response = requests.post(url, headers=headers, json=data)

-- p

print(f'Status: {response.status_code}')
  print(f'Returned: {response.json()}')

-- p

#+end_src

-- results/

Status: 200
  
  Returned:
  {
    "hits": [
      {
        "id": "100",
        "filename": "Example State Names",
      }
    ]
  }

-- /results

-- p

TODO: Link up other version of getting pages via GET


-- categories
-- Python 

-- metadata
-- date: 2022-06-02 21:27:04
-- id: 2a2thdvn
-- status: scratch
-- type: post
-- SCRUBBED_NEO: false
-- site: aws