I have built a python server-side script which is required to retrieve a small JSON from the body of a post request.
The request body is of the form - {name : value} only.
I have tried using (cgi.FieldStorage()).getvalue(...) but to no luck. Can you please let me know how to extract such a JSON from the post request sent to it.
Step1: make sure your server supports CGI programming
Step2: The scripts to be executed should be in the /var/ww/cgi-bin directory of the HTTP server. Make sure this is location of the script
Related
I am trying to return JSON data from a Python CGI script running on a local Apache server (xampp).
The script itself runs fine with no issues and the expected result is returned, however despite the script outputting the header
print("Content-type: application/json; charset: utf-8")
when an AJAX request is made (from a client-side javascript) to the same script, the request fails. After running
#!C:\Python39\python.exe -u
import cgi
cgi.test()
exit(0)
It turns out the accepted response headers under the Shell Environment: section are as follows
HTTP_ACCEPT
text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
This is causing the JSON response to be sent as HTML, which is breaking the request, since the response is sent in JSON but the request only accepts responding with HTML.
I tried fixing this by adding the accepted MIME type in the .htaccess file within the /cgi-bin directory with
AddType application/json .py
But this doesn't work and I don't expect forcing my .py script to be interpreted as a .json file to be the desired solution, since I want the output as JSON, not the file itself.
The Apache documentation here claims non-html content can be sent but it does not give an example on how to accomplish this.
I also have many PHP files (in /htdocs) in my project which do the exact same thing (outputting a JSON response which is accessed via an external AJAX request) however, beyond simply outputting the JSON header in the script, they do not require any modification to the server's accepted output and work properly without any further intervention.
I can't seem to find any other solutions related to forcing the server to respond with JSON data instead of HTML text for CGI scripts.
After some investigation, it turns out this was a CORS issue and not a conflict with the accepted Content-type and the fact that calling
cgi.test()
Only outputs HTML headers, regardless of whatever the expected server response should be.
I am trying to generate a request and response template from a WSDL.
I know SOAP UI can do this, but I need to use Python in my case.
I have seen that there is a python lib called zeep, but it seems to be targeted more towards setting up a soap client and performing calls.
How can I get the request from the WSDL?
Here is an example I have been using:
https://www.tutorialspoint.com/wsdl/wsdl_example.htm
You can create the request XML documents with zeep, see http://docs.python-zeep.org/en/master/client.html#creating-the-raw-xml-documents
I need to initiate an action on server via sending the HTTP request with GWT-RPC call in body section. I'm completely new in GWT subject so please forgive my lack of knowledge. In Java I was able to perform this action via sending HTTP POST request with proper headers and GWT-RPC in body so I tried to do the same in Python with requests library.
Unfortunately, when sending GWT-RPC call I got response:
//EX[2,1,["com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException/3936916533","This application is out of date, please click the refresh button on your browser. ( Malformed or old RPC message received - expecting version between 5 and 7 )"],0,7]
I read few topics:
Manually generating x-gwt-rpc from Python,
com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException
and as I understood there's no way to send the GWT-RPC call from other platform than Java without some additionall effort. Please correct me and advise if I'm wrong.
I am trying to access Siebel WSDL through python module.
My End Scenario is creating Service request in Siebel through external link.
I have tried,
Requests, Suds and soapPY.
When Importing WSDL file to SOAP-UI after making changes to URL and appending user-name and password to same and making changes in body, Its working for me and giving 200 server response.
When trying to access the same with postman(rest client) and giving URL with user name and password added. And passing the required XML as part of body I am getting 500 internal server error.
Not understanding where difference is coming in the way the request is going through soapUI and postman.
What difference in I have to make, to make it work with postman.
What is the right way to consume a WSDL service in python.
SOAP Input:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:aud="http://siebel.com/Service/ServiceReqs" xmlns:aud1="http://www.siebel.com/xml/%20Service%20Request%20IO">
<soapenv:Header/>
<soapenv:Body>
<aud:SRQueryByExample_Input>
<aud1:ListOfServiceRequestIo>
<aud1:ServiceRequestOpen Operation="?">
<aud1:IntegrationId>0000123</aud1:IntegrationId>
</aud1:ServiceRequestOpen>
</aud1:ListOfAudetemiServiceRequestIo>
</aud:SRQueryByExample_Input>
</soapenv:Body>
</soapenv:Envelope>
I need to know here if Integration ID is something that I need to pass dynamically how to achieve same.
Many thank for your time
If you are getting a 500 error, that means the request is stuck at the web server, and has not yet hit the siebel server behind it. If the error is due to something missing in the xml, you will get a "SBL-" error code in the response. Until you get that, and are getting 500 errors, the request SOAP has not yet hit the siebel server.
I don't know python, but my suggestion would be to capture the RAW message going from your python script and compare that to the RAW message in SOAP-UI. Specially check the SOAPAction string, it should have a forward slash (/) and a colon (:). "Content-Type", "text/xml"
For further debugging, you will have to check the webserver logs to see how the message arrives there.
I have Python-Eve running with MongoDB on a Ubuntu VM. I am trying to write an api to handle POST requests from an Iridium RockBLOCK modem. I have tested the API with Chrome Postman, and am able to successfully POST data.
When I try and send messages from my RockBLOCK I get 422 error messages on the VM. I am pretty sure this is because the RockBLOCK is not able to handle XML or JSON data, and is set up to simply look for an HTTP 200 response.
So how would I setup eve to respond with solely HTTP 200 when the POST request is received?
API Format taken from RockBLOCK Web Services Guide.
The 422 is returned from Eve when a validation error occurs. I would look into your request payload and make sure it adheres to validation rules. A typical example of a response like this would be when you have a unique rule for a field, and a POST comes in with an already used value for that field.
So how would I setup eve to respond with solely HTTP 200 when the POST request is received?
Right now you can disable either JSON or XML responses by respectively setting JSON = False or XML = False, but not both. Since Eve is a Flask application you could look into changing the response on the flight but again, given the error you are getting I don't think that is the problem you are facing right now.