Debugging an issue with launchd and python requests

I am trying to get a python script to regularly fill out a google form on Mac OS X. (side note RIP cron :(., I do NOT like launchd)


I have been able to get almost everything done I need to.

  1. The python script works when I run it separately.
  2. launchd works by running my script as long as I do not include the posting to google forms bits.


When I take out "import requests" and "requests.post(myURL,mySubmission)" the launchd/script combo work fine.


Is there some reason python requests are not working with launchd? Any help would be appreciated.

MacBook Pro 13", OS X 10.11

Posted on Mar 25, 2020 8:14 PM

Reply

Similar questions

2 replies

Mar 27, 2020 2:48 PM in response to VikingOSX

VikingOSX wrote:

Couple of thoughts. See if there is an update for that third-party requests module, and then try your Python script again using requests as previous. I may have this backward, but I believe scripts that have no GUI interaction are placed in LaunchDaemons, and scripts with GUI interaction are placed in LaunchAgents folders.

I just downloaded the latest requests module. I put the launchd plist in the LaunchAgents folder of my ~/Library user folder.

am wondering if you may have to pass a user-agent string in a header dictionary along with your request to satisfy Google?

Okay. What do you mean by this?

Plan B may be to remove the third-party requests module and use the standard, import urllib.request that is already in Python3, or if you are using Python 2.7.16 or .17, use the import urllib2.Request approach. I know that both of these suggest using the third-party requests module.

I'll check this out.

f you are attempting to use the Python3 that was included with Xcode 11 or its associated command-line tools, I wonder out loud what Apple excluded, and that Python3 is quite outdated now too. Ideally, you would be using an installation of Python 3.8.2 from Python.org — with the added request module.

I am using the most updated python3 from python.org

Mar 26, 2020 6:21 AM in response to mahongue

Couple of thoughts. See if there is an update for that third-party requests module, and then try your Python script again using requests as previous. I may have this backward, but I believe scripts that have no GUI interaction are placed in LaunchDaemons, and scripts with GUI interaction are placed in LaunchAgents folders.


I am wondering if you may have to pass a user-agent string in a header dictionary along with your request to satisfy Google?


Plan B may be to remove the third-party requests module and use the standard, import urllib.request that is already in Python3, or if you are using Python 2.7.16 or .17, use the import urllib2.Request approach. I know that both of these suggest using the third-party requests module.


If you are attempting to use the Python3 that was included with Xcode 11 or its associated command-line tools, I wonder out loud what Apple excluded, and that Python3 is quite outdated now too. Ideally, you would be using an installation of Python 3.8.2 from Python.org — with the added request module.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Debugging an issue with launchd and python requests

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.