Package: openpost
OpenPostThe 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 ModuleThe module provides anOpenPostclass 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:pipinstallopenpostOpenPost Objectclassopenpost.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.bodyAdditional 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_nameThe 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_dataThekey:valuedata to include in the POST request html form.  Eachkeywill be entered as a separate item in the form.{str}OpenPost.headersAdditional 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_fileAn indicator as to whether or not to keep the output html file after opening in browser.{bool}OpenPost.new_tabAn 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_liveThe number of seconds to delay before removing the output html file (0-60).  This is ignored if thekeep_fileproperty is set toTrue.{str}OpenPost.urlThe url for the action field in the html form.{bool}OpenPost.writtenAn indicator as to whether or not the html file has already been written.(Depricated since v0.3)MethodsOpenPost.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 keyOpenPost.delete_key(key)Remove a data key used for the POST request form.Argument:{str}key -- Key to be removed from the formOpenPost.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.Exampleimportopenpostposter=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>'ifposter.send_post():print('POST request sent.')else:print('Error sending POST request.')Command Line UtilityThis 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 therepository on GitHubfor full usage information and to download.