Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • 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.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • 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

Hello

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

[CODE lang="python" title="Python"]import requests

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

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

print(x.text)
[/CODE]

Here is the code on the server side:

[CODE lang="php" title="Server Side PHP Script"]<?php
print_r($_REQUEST);
?>[/CODE]

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:

[CODE lang="html" title="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>[/CODE]

The web page just displays Array(). Does anyone know what the issue could be?
 
Hey LTomy, thanks for the reply!

So if I type in the URL in my browser, I do see the page. And its contents are just "Array()" If I don't attempt to post to the page it will stay blank so I think that Apache is finding the page.
 
Similar to this? I am oddly getting the same error with this request as the post request.

[CODE lang="python" title="request get"]import requests

url = 'https://domain.com/page.php'

x = requests.get(url)

print(x.text)[/CODE]

If I add print(x.headers) I get the following back:

[CODE title="request.headers"]{'Date': 'Sun, 10 Jan 2021 17:56:24 GMT', 'Server': 'Apache', 'Content-Length': '226', 'Keep-Alive': 'timeout=5, max=75', 'Connection': 'Keep-Alive', 'Content-Type': 'text/html; charset=iso-8859-1'}[/CODE]
 
Last edited:
So the problem seems to be that for some reason, apache can not find the page requested.
What if you try with http instead of https?
The URL you type in your web browser is the same you use within your python code?
Juste to make sure, you replaced 'domain.com' by the address of your website, right?
 
Last edited:
Okay interesting don't know why that would be the case. I did verify that the urls were the same and the browser can find on both machines. I tried HTTP but no luck, got the same error.

Went ahead and tried to fool with the domain name in the python script just to see what would happen and immediately got a bunch of errors from the python script. So it seems like it is seeing the domain server, but maybe not the page.
 
The reason that mod blocks the requests of your script is probably due to how the mod is configured.
It could be a lot of things. Do you have access to an other computer on which you can try the script?
 
Back
Top Bottom