Search code examples
pythongoogle-app-enginegoogle-cloud-platformspotifyreddit

AppEngine - IOError: [Errno 2] No such file or directory:


I'm making a web app with AppEngine that uses the Spotify and Reddit APIs and have it working locally with dev_appserver.py, but when I upload my project and try the exact same thing on the website version, I get an error:

Traceback (most recent call last):
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/350d926c06a7e859/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/350d926c06a7e859/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
...
...

  File "/base/data/home/apps/s~kabloombox-219016/20190116t005128.415435515961651480/main.py", line 274, in post
    scan_subreddit(language, access_token)
  File "/base/data/home/apps/s~kabloombox-219016/20190116t005128.415435515961651480/main.py", line 190, in scan_subreddit
    reddit = praw.Reddit(client_id=CLIENT_ID_REDDIT, client_secret=CLIENT_SECRET_REDDIT, user_agent=USER_AGENT)
...
...

  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/350d926c06a7e859/python27/python27_dist/lib/python2.7/platform.py", line 165, in libc_ver
    f = open(executable,'rb')
IOError: [Errno 2] No such file or directory: '/base/alloc/tmpfs/dynamic_runtimes/python27g/350d926c06a7e859/python27/python27_dist/python'

I get this error after submitting a form, which then is supposed to run a web scraper but just errors instantly instead. I found a lot of people with the same No such file or directory error on their own files that they made and just needed to change app.yaml, but /base/alloc/tmpfs/dynamic_runtimes/python27g/350d926c06a7e859/python27/python27_dist/python is some random file/folder and I have absolutely no idea what I'm supposed to make of it.


Solution

  • You can either change your praw initialization to prevent it from calling platform.platform():

    r = praw.Reddit(user_agent='...', disable_update_check=True)
    

    Or patch platform.platform() to return a string literal in appengine_config.py:

    import platform
    
    def patch(module):
        def decorate(func):
            setattr(module, func.func_name, func)
            return func
        return decorate
    
    @patch(platform)
    def platform():
        return 'AppEngine'