Skip to main content

A module to help prepare and execute html POST requests.

Project description

OpenPost

The OpenPost project is intended to allow the creation of an html POST request file, and optionally open the request in a browser window. The project provides both a Python module for use within a program, and a stand-alone Python script that can be used on the command line.

Python Module

The module provides an OpenPost class object to prepare and submit html POST requests using the default system internet browser. It works by writing a temporary html file locally, and then opens the file in the browser. Upon opening, the file will immediately submit a form via POST to the target url.

Install using:

pip install openpost

OpenPost Object

class openpost.OpenPost(url=None, file_name=None, keep_file=False, time_to_live=5, form_data={}, headers=None, body=None, new_tab=True)

Create a new OpenPost object. All parameters should be passed as keyword arguments. Each parameter is also made available as a property as described below.

Properties

  • {str} OpenPost.body
    Additional lines to be added to the <body> section of the html document. If the value is an array, each element will be added on a separate line.
    (Added in v0.3)

  • {str} OpenPost.file_name
    The path and name to use for the output html file. If no filename is set, it will default to 'OpenPost.html' in the current directory.

  • {dict} OpenPost.form_data
    The key:value data to include in the POST request html form. Each key will be entered as a separate item in the form.

  • {str} OpenPost.headers
    Additional lines to be added to the <head> section of the html document. If the value is an array, each element will be added on a separate line.
    (Added in v0.3)

  • {bool} OpenPost.keep_file
    An indicator as to whether or not to keep the output html file after opening in browser.

  • {bool} OpenPost.new_tab
    An indicator as to whether or not to open the page in a new browser tab. Note that some browsers will force opening in a new tab regardless of this setting.
    (Added in v0.3)

  • {float} OpenPost.time_to_live
    The number of seconds to delay before removing the output html file (0-60). This is ignored if the keep_file property is set to True.

  • {str} OpenPost.url
    The url for the action field in the html form.

  • {bool} OpenPost.written
    An indicator as to whether or not the html file has already been written.
    (Depricated since v0.3)

Methods

  • OpenPost.clear_data()
    Clears the data used for the POST request form.

  • OpenPost.add_key(key, value)
    Add or update a data key used for the POST request form.
    Arguments:

    • {str} key -- Key used in the form
    • {str} value -- Value for the specified key
  • OpenPost.delete_key(key)
    Remove a data key used for the POST request form.
    Argument:

    • {str} key -- Key to be removed from the form
  • OpenPost.make_html()
    Make the content of the output html file.
    Returns a string containing the content of the html file, or '' if an error occurred.

  • OpenPost.write_html()
    Prepare and write the output html file.
    Returns True if the file was successfully written, otherwise False.

  • OpenPost.send_post()
    Open the output POST html file in the default web browser, automatically writing the output html file if it has not already been written. Automatically removes the output file after the specified time delay unless the keep_file flag has been set.
    Returns True if the file was successfully opened, otherwise False.

  • OpenPost.version()
    Returns the version number of the openpost module.

Example

import openpost

poster = openpost.OpenPost()
poster.url = 'https://www.somesite.org/login.php'
poster.file_name = 'my_special_filename.html'
poster.add_key('name', 'My Name')
poster.add_key('id', 'My_ID')
poster.add_key('password', 'My_Secret_Password')
poster.body = r'<p>You are being redirected.  Please stand by...</p>'
if poster.send_post():
  print('POST request sent.')
else:
  print('Error sending POST request.')

Command Line Utility

This utility allows you to open a POST request in a browser window from the command line. It works by writing a temporary html file locally, and then opens the file in the browser. Upon opening, the file will immediately submit a form via POST to the target url.

Please see the repository on GitHub for full usage information and to download.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openpost-0.3.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

openpost-0.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file openpost-0.3.tar.gz.

File metadata

  • Download URL: openpost-0.3.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6

File hashes

Hashes for openpost-0.3.tar.gz
Algorithm Hash digest
SHA256 093eb3b6ca9127eed4f16ea912309e44957a2fdc0620773a18813e9a29e98e3b
MD5 3aa2f3f210289ea4b76502338d8109fd
BLAKE2b-256 3f43fb941d1ecbb99c1bf2a30870123574ec075c8a76ff3c2399db0b8cdfa6f8

See more details on using hashes here.

File details

Details for the file openpost-0.3-py3-none-any.whl.

File metadata

  • Download URL: openpost-0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6

File hashes

Hashes for openpost-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fb26a2f4ebc64721aa047cbf93540780d752f75a103ceb77d20fd4a507385aab
MD5 a734f0b6d538b45668d288984c879786
BLAKE2b-256 d78cb68f798e0775403155936e283cffa6d1b4e8328b75f5662874a16e3ca96c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page