What is the link to the google documentation for what you are trying to do?
Python Request Script won't work with Laravel Process Facade
Hi all,
I hope someone can point me in the right direction here. But I'm having this odd issue with the "Process" facade trying to run a python script that connects to Google and returns a status 200 (using python's REQUEST library).
This is my Laravel Code:
use Illuminate\Support\Facades\Process;
public function python()
{
$pythonFolder = $this->pythonFolderPath;
$pythonEnvProgram = $this->pythonEnvProgram;
$result = process::path($pythonFolder)->run([$pythonEnvProgram, 'ConnectToGoogle.py']);
if($result->successful()){
return $result->output();
}
else {
dump($result);
return $result->errorOutput();
}
}
this is the python script I'm trying to run:
import requests
def check_google_connection():
# URL of Google's homepage
url = "https://www.google.com/"
try:
# Send a GET request to the URL
response = requests.get(url)
# Check if the status code is 200
if response.status_code == 200:
print("Successfully connected to Google's homepage.")
print(f"Status code: {response.status_code}")
return True
else:
print(f"Connection failed. Status code: {response.status_code}")
return False
except requests.RequestException as e:
print(f"An error occurred while connecting to Google: {e}")
return False
if __name__ == "__main__":
check_google_connection()
the response I get is this:
An error occurred while connecting to Google: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by NameResolutionError(": Failed to resolve 'www.google.com' ([Errno 11001] getaddrinfo failed)"))
which indicates that my computer is not connected to the internet or some sort. But if I run the python Script in the command line, it seems to work just fine and returns a connection.
I've even tried to run a simple helloWorld python script to make sure I understood how to use the "process" facade. And I am getting the correct return. So the issue is not the "Process" facade or my laravel app (which I'm running locally)
Can someone point me in the right direction? Is the issue with the Python Request Library that does not play well with Laravel?
Please or to participate in this conversation.