0

外部サーバーにあるhtmlフォームでPOSTされた変数フォームコンテンツを取得する方法を知りたいです。

私はこのコードを持っています:

myserver.py

import BaseHTTPServer

HOST_NAME = ''
PORT_NUMBER=8000

postVars = ''

class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):

    def do_POST(s):
        global postVars
        s.send_response(200)
        s.end_headers()
        varLen = int(s.headers['Content-Length'])
        postVars = s.rfile.read(varLen)
        print postVars

server_class = BaseHTTPServer.HTTPServer
httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)

try:
    httpd.handle_request()
except KeyboardInterrupt:
    pass

print postVars
httpd.server_close()
postVars is valued during the Handler, but not after MyHandler

現在、これをコンソールに出力します

user=jhon&domain=domain.com&pass=mypassword

各変数を抽出し、それらを使用して後続の bash スクリプトを呼び出したいと思います。

私が達成したいことの例:

import os
value1="user"
value2="domain"
value3="pass"
os.system("./usersprivetes.sh %s %s %s" % (value1,value2,value3))

コメントとご協力ありがとうございます。

4

1 に答える 1