1

I have a piece of python code on my machine that does a few things, one of which includes interacting with the Yelp API, which uses oauth2.

I've scheduled this piece of code to run via a cron job everyday at 2PM. When the job executes, I get the following error:

Traceback (most recent call last):
  File "/Users/.../.../.../project.py", line 18, in <module>
    from yelp.oauth1_authenticator import Oauth1Authenticator
  File "/Users/.../.../.../yelp/oauth1_authenticator.py", line 2, in <module>
    import oauth2
ImportError: No module named oauth2

This call to import oauth2 is part of the oauth1_authenticator.py file in the Yelp API, which exists here:

import oauth2


class Oauth1Authenticator(object):



def __init__(
    self,
    consumer_key,
    consumer_secret,
    token,
    token_secret
):
    self.consumer = oauth2.Consumer(consumer_key, consumer_secret)
    self.token = oauth2.Token(token, token_secret)

def sign_request(self, url, url_params={}):
    oauth_request = oauth2.Request(
        method="GET",
        url=url,
        parameters=url_params
    )
    oauth_request.update(
        {
            'oauth_nonce': oauth2.generate_nonce(),
            'oauth_timestamp': oauth2.generate_timestamp(),
            'oauth_token': self.token.key,
            'oauth_consumer_key': self.consumer.key
        }
    )
    oauth_request.sign_request(
        oauth2.SignatureMethod_HMAC_SHA1(),
        self.consumer,
        self.token
    )
    return oauth_request.to_url()

The error occurs and nothing else in the program is executed.

However, when I open up the program in my editor and simply run it, everything works fine. No errors returned. For awhile, I thought this was in part to how oauth2 was installed on my machine -- similar to this -- but now I'm not so sure.

Community
  • 1
  • 1
derks
  • 53
  • 10

0 Answers0