• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.
    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python Python HTTP Post to Apache

Feynman137

New Coder
Hello

I have a super simple python script requesting to HTTP post to one of my web pages with PHP script.

Python:
import requests

url = 'https://domain.com/page.php'
myobj = {'test': '1'}

x = requests.post(url, data = myobj)

print(x.text)

Here is the code on the server side:

Server Side PHP Script:
<?php
print_r($_REQUEST);
?>

Based on what I've read this should be formatted correctly to send to my web page. But I keep getting the following back from my python script:

HTML error:
<head><title>Not Acceptable!</title></head><body><h1>Not Acceptable!</h1><p>An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.</p></body></html>

The web page just displays Array(). Does anyone know what the issue could be?
 

LTomy

Active Coder
Staff Team
Guardian
Eum, do you have a VPN ahah?
** That is probably not your IP address if it works in your web browser.

I am really lost... Could it be a problem with PHP? Can you retrieve an HTML document?
 

LTomy

Active Coder
Staff Team
Guardian
I am seriously lost as to why the requests of your script are blocked... Since the requests of the script comes from the same IP address and same port as when you use your web browser, I do not know how the server detects the requests are from the script.
 

LTomy

Active Coder
Staff Team
Guardian
Oh, it may be that when your script sends requests, in the header, it indicates that they are from a script (The same way your navigator indicates that it is Firefox, Chrome..). 'Mod_Security' may block requests from software that are not web browsers.
 

Feynman137

New Coder
You may be right though they may just be allowing scripts that are coming from specific browsers. HTTP requests are going through now so whatever they did it works. Just hope I don't run into this with every new IP I get.
 
Top