简体   繁体   English

使用python flask从客户端向服务器发送和接收XML文件

[英]Send and recieve an XML file from client to server using python flask

I need to send and receive a XML file stored at a client machine to a flask server. 我需要向客户端服务器发送和接收存储在客户端计算机上的XML文件。 I am able to do the same for JSON file using requests but the same is not happening with XML. 我可以使用请求对JSON文件执行相同的操作,但XML不会发生相同的操作。

This is my server side code 这是我的服务器端代码

app = Flask(__name__)
api = Api(app)
app.config["DEBUG"] = True


@app.route('/',methods=['GET','POST'])
def home():
    print ("************SERVER CALLED ***********")
    req_data= request.get(silent=True)

app.run(host='192.168.37.129')

and this is the client code 这是客户代码

getlatestfile = os.getcwd()+fileseparator+"MSF"
getlatestfile=getlatestfile+fileseparator+"*.xml"
list_of_files = glob.glob(getlatestfile)
if list_of_files:
    msfFile = max(list_of_files, key=os.path.getctime)
    print ("[+] Sending latest MSF file which is..."+msfFile)
    with open(msfFile) as xml:

        response = requests.post('http://192.168.37.129:5000/', data=open(msfFile).read())
        print ('response from server:',response.text)

        #k=response.text
        #print(res1.content);
        print("[+] Received response from server...Intiating run of commands as directed by server \n")


else:
    print("No Result file present in the XML directory location/file could be corrupted.")

I am getting the following error on my server and host respectively 我分别在服务器和主机上收到以下错误

AttributeError: 'Request' object has no attribute 'get'

client 客户

File "test.py", line 26, in <module>
    response = requests.post('http://192.168.37.129:5000/', data=open(msfFile).read())
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 490, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', error(32, 'Broken pipe'))

ANy help will be highly appreciated 非常感谢您的帮助

try matching your port numbers for client and server. 尝试匹配您的客户端和服务器的端口号。 Also, instead of writing 另外,不要写

req_data= request.get(silent=True) 

write

return jsonify(request.json)

and change 并改变

response = requests.post('http://192.168.37.129:5000/', data=open(msfFile).read())

to

response = requests.post('http://192.168.37.129:5000/', json=data)    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Flask在Python中将数据从服务器发送到客户端? - How to send data from server to client in Python using Flask? 如何使用 python flask web 服务从服务器发送文件以及如何从客户端获取这些文件? - how to send files using python flask web service from server and how to get those files from client? 使用 TCP 将图像文件从客户端发送到服务器的 Python 程序 - A program to send an image file from client to server in python using TCP 如何将信息从客户端发送到服务器(Flask-python) - How to send information from client to server (Flask - python) Python / Flask / Ajax:从客户端向服务器发送字典密钥 - Python / Flask / Ajax : send a dict key from client to server 如何在 Flask 中创建 Excel 文件并将其从服务器发送到客户端 - How to create and send excel file from server to client in flask UDP服务器和客户端无法发送和接收消息 - UDP Server and Client Failing to Send And Recieve Messages 使用XMLRPC将文件从客户端发送到服务器? - Send file from client to server using XMLRPC? 有没有办法使用 flask-python 通过 api 从服务器发送 zip 文件? - Is there a way to send a zip file from server via api using flask-python? 如何从客户端接收整数和字符串的缓冲区并正确存储它们? (cpp服务器,python客户端) - How to recieve a buffer of ints and strings from a client , and store them right? (cpp server , python client)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM