I am trying to connect to twitter api using oauth2. But the code is not working as it shows the error AttributeError: 'module' object has no attribute 'Consumer'
Is there any update in the oauth2 package? If there is, then what is the another way to do same?
def oauth_req(self, url, http_method="GET", post_body=None,
http_headers=None):`enter code here`
config = self.parse_config()
consumer = oauth.Consumer(key=config.get('consumer_key'), secret=config.get('consumer_secret'))
token = oauth.Token(key=config.get('access_token'), secret=config.get('access_token_secret'))
client = oauth.Client(consumer, token)
resp, content = client.request(
url,
method=http_method,
body=post_body or '',
headers=http_headers
)
return content
Any help would be really appreciated. Thanks in advance!
Related
I have used the following guide - https://developer.ebay.com/marketplace-account-deletion
So I've created a flask based website on python and uploaded in Heroku,
https://ebay-deletion.herokuapp.com/
If you create a query parameter, for the challenge code like so:
https://ebay-deletion.herokuapp.com/?challenge_code=123
It returns a challenge response and doc type (JSON).
I don't understand but why but I get this error below:
Notification delivery failed with HTTP status code 405 from https://ebay-deletion.herokuapp.com. Please ensure that the marketplace account deletion notification endpoint is ready to receive notifications.
Any thoughts on how to solve this?
Ebay's help page is just so terrible. Their python code examples for hashing in the top link have semi-colons after each line! It's close to completely useless.
Here is the Python Flask code:
#app.route('/')
def index():
args = request.args
args_dict = args.to_dict()
try:
resp_hash = hashlib.sha256(
args_dict['challenge_code'].encode() + verification_token.encode() + endpoint.encode())
resp = {'challengeResponse': resp_hash.hexdigest()}
return jsonify(resp), 200, {'content-type': 'application/json'}
except KeyError:
err = {'status_code': 400, 'message': 'no challenge response in params'}
return jsonify(err), 400, {'content-type': 'application/json'}
I have a simple Python server to verify Google oauth2 id_tokens. When this code executes it throws the error AppIdentityError: Wrong recipient:
def verify():
id_token = request.form['id_token']
status = {}
if id_token is not None:
try:
jwt = verify_id_token(id_token, config['google']['clientId'])
status['valid'] = True
status['jwt'] = jwt
except AppIdentityError:
status['valid'] = False
status['message'] = "Invalid id token"
pprint.pprint(status)
response = make_response(json.dumps(status))
response.headers['Content-Type'] = 'application/json'
return response
What does AppIdentityError: Wrong recipient mean and how can I address it?
The JWT that you are trying to verify includes an audience (aud) value. The error is the result of the aud value being mismatched with what is expected.
I'm not certain which library you're using, but in the identity-toolkit-python-client package the VerifyGitTotken function looks at the project_id and client_id values that are provided to verify the JWT.
When I encountered this error, it turned out that my gitkit-server-config.json file mismatched what was provided by the Google developers console. The values are provided on the API Manager >> Overview >> Identity Toolkit API page.
I corrected my json file, and the error went away.
We are working on a project where the python client makes RPC call on a Java method
String uploadFile(String name, String Id)
Now, this client code has to send an attachment!
def sendFile(self, Id, filePath):
uploadFileMethod = getattr(self.client.service, "uploadFile")
attachment_id = Id
attachment_content = (filePath, attachment_id)
with_soap_attachment(uploadFileMethod, attachment_content)
Since, suds does not support attachments and I luckily found a scrpit mentioned that it does. The script is mentioned here
Now, when I execute, I am getting the error
AttributeError: 'Client' object has no attribute 'location'
line 75, in with_soap_attachment
Can anyone help me why its coming and how to fix it?
thanks
what worked for me was to replace
request = Request(suds_method.client.location(), request_text)
with
request = Request(soap_method.location(), request_text)
I just updated to Twython 2.3.4, but now my Twitter auth stops working. It fails on the ' auth_props = twitter.get_authentication_tokens()' line. Any idea what went wrong? Thanks in advance!
The python code to do Twitter auth using Twython is below:
def begin_auth(request):
twitter = Twython(
twitter_token = TWITTER_KEY,
twitter_secret = TWITTER_SECRET,
callback_url = request.build_absolute_uri(reverse('portnoy.views.thanks'))
)
# Request an authorization url to send the user to...
auth_props = twitter.get_authentication_tokens()
I have the following error on the line above: TwythonAuthError: "Seems something couldn't be verified with your OAuth junk. Error: 401, Message: Failed to validate oauth signature and token"
# Then send them over there, durh.
request.session['request_token'] = auth_props
return HttpResponseRedirect(auth_props['auth_url'])
def thanks(request, redirect_url='/'):
c = RequestContext(request)
# for permanent ones and store them...
twitter = Twython(
twitter_token = TWITTER_KEY,
twitter_secret = TWITTER_SECRET,
oauth_token = request.session['request_token']['oauth_token'],
oauth_token_secret = request.session['request_token']['oauth_token_secret']
)
# Retrieve the tokens we want...
authorized_tokens = twitter.get_authorized_tokens()
request.session['request_tokens'] = authorized_tokens
debug('thanks', request.session['request_tokens'])
user = User.objects.filter(username=authorized_tokens['screen_name'])
if user.exists():
user = user[0]
user.backend='django.contrib.auth.backends.ModelBackend'
auth.login(request,user)
else:
return render_to_response('twitter_register.html', c)
return HttpResponseRedirect(redirect_url)
I'm the author of Twython.
What version of Requests are you running under the hood? There was recently an issue where people kept running into various OAuth-related errors due to an upstream bug. Curious if it's related to that...
I ran into the same problem myself.
It doesn't seem to work if you are testing locally.
Here's what I did to fix it:
Edit your hosts file (on OSX its located at /private/etc/hosts). Add the line:
127.0.0.1 myapp.com
Goto your Twitter App Settings and click on the "Settings" tab. Set your callback URL to:
http://myapp.com:8000/thanks
Make sure you set the port number and url correctly.
Hope that helps!
Hi i have just started to evaluate different options for python>Twitter api:s.
I have written some code looking at the examples in the Twython package but i always end up getting the same error.
AttributeError: 'Twython' object has no attribute 'auth'
I also get the same error running the included core_example files.
I am running "2.0.0" from git.
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python /Users/skjortan/dev/trunk/3rdPartyLibs/twython/core_examples/current_trends.py
Traceback (most recent call last):
File "/Users/skjortan/dev/trunk/3rdPartyLibs/twython/core_examples/current_trends.py", line 5, in <module>
trends = twitter.getCurrentTrends()
File "/Library/Python/2.7/site-packages/twython-2.0.0-py2.7.egg/twython/twython.py", line 167, in <lambda>
return lambda **kwargs: self._constructFunc(key, **kwargs)
File "/Library/Python/2.7/site-packages/twython-2.0.0-py2.7.egg/twython/twython.py", line 188, in _constructFunc
content = self._request(url, method=method, params=kwargs)
File "/Library/Python/2.7/site-packages/twython-2.0.0-py2.7.egg/twython/twython.py", line 205, in _request
response = func(url, data=myargs, auth=self.auth)
AttributeError: 'Twython' object has no attribute 'auth'
Process finished with exit code 1
I noticed your question - I'm the author of Twython. A fix has been committed and pushed out for a 2.0.1 release. If you update your installation this should no longer be an issue.
Thanks, sorry for the hassle! Bug that slipped by our 2.0.0 release.
But its really has no attribute 'auth' but it has methods like:
def get_authentication_tokens(self):
"""Returns an authorization URL for a user to hit."""
def get_authorized_tokens(self):
"""Returns authorized tokens after they go through the auth_url phase."""
And this is sample from django-twython how its author make auth
def begin_auth(request):
"""
The view function that initiates the entire handshake.
For the most part, this is 100% drag and drop.
"""
# Instantiate Twython with the first leg of our trip.
twitter = Twython(
twitter_token = settings.TWITTER_KEY,
twitter_secret = settings.TWITTER_SECRET,
callback_url = request.build_absolute_uri(reverse('twython_django_oauth.views.thanks')))
# Request an authorization url to send the user to...
auth_props = twitter.get_authentication_tokens()
# Then send them over there, durh.
request.session['request_token'] = auth_props
return HttpResponseRedirect(auth_props['auth_url'])
apparently twitter api and does not allow normal login, just for oauth, creates the application on Twitter and OAuth Settings tab from there takes the data from OAuth Settings, and methods of oauth in:
http://pydoc.net/twython/1.4.5/twython.twitter_endpoints