Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Electrodude's avatar

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?

0 likes
8 replies
jlrdw's avatar

What is the link to the google documentation for what you are trying to do?

1 like
Electrodude's avatar

Hi jlrdw,

I'm not sure what the question is? I'm trying to run a GET request to Googles homepage using Python Request Library, then use Laravels 'process' facade to run the python code.

Also, I can't post links on this webpage.

azimidev's avatar

When you run the script directly from the command line, it works because it’s using your local environment’s network configuration and permissions. However, when Laravel runs it through the Process facade, it might be running in a different environment or restricted network context that doesn’t have access to the internet, hence the DNS resolution error.

1 like
Electrodude's avatar

@azimidev

Seems a bit of a bummer if the process can't run the script as an external process that connects to the internet. I would assume that the env(APP_ENV=FALSE) won't even work in this case?

azimidev's avatar

@Electrodude APP_ENV false is incorrect. should be production, local, testing etc

Try Running a Basic Network Command: You can run something simple like a ping command through Process to check if Laravel has any network access at all:

$result = Process::run(['ping', '-c', '4', 'google.com']);
if ($result->successful()) {
    echo $result->output();
} else {
    echo $result->errorOutput();
}
1 like
Electrodude's avatar

@azimidev

Thanks for the input. I'll try it in the morning UK time and report back.

Incidentally, I've tried using the HTTP facade for the exact test. And that seemed to work just fine (getting response from Google)

Maybe I might try to Jerry rig the HTTP facade with the process Facade and see if I can 'open' a connection between my laravel app and the internet.

But will update you later today.

And thanks for the help! :)

1 like
Electrodude's avatar

Yea nothing seems to work (or I not knowing how to make it work)

I'll stick to cron jobbing it and collect the data as json instead.

Again! Thanks for the help! Truly appreciate it 🙏

Please or to participate in this conversation.