SSL required error for twython API call - python

I am trying to use twython to make API call for twitter and get the tweets. And I am receiving 403 error from twitter that says SSL is required. Can anyone help me how to finish this simply query?
Btw, I am using python 2.7. The OS is Windows 7.
from twython import Twython
tw = Twythonfrom twython import Twython(app_key=app_key, app_secret=app_secret, oauth_token=oauth_token, oauth_token_secret=oauth_token_secret)
search = tw.search(q = 'Sandra')
for result in search:
print result
And the error message
traceback (most recent call last):
File "C:\Users\local.admin\My Documents\LiClipse Workspace\test\TwythonTest.py", line 33, in <module>
search = tw.search(q = 'Sandra')
File "C:\Python27\lib\site-packages\twython\twython.py", line 133, in <lambda>
return lambda **kwargs: self._constructFunc(key, **kwargs)
File "C:\Python27\lib\site-packages\twython\twython.py", line 149, in _constructFunc
content = self._request(url, method=fn['method'], params=kwargs)
File "C:\Python27\lib\site-packages\twython\twython.py", line 218, in _request
retry_after=response.headers.get('retry-after'))
twython.twython.TwythonError: Twitter API returned a 403 (Forbidden), SSL is required

Related

Tweepy Python returns: 401 Unauthorized

So, I was trying to like a Tweet using Tweepy, but this error is occurring:
Traceback (most recent call last):
File "c:/Users/User/Desktop/VScode/Python/FibraBot_home/bottwitter2.py", line 32, in <module>
tweet.favorite()
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tweepy\models.py", line 371, in favorite
return self._api.create_favorite(self.id)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tweepy\api.py", line 46, in wrapper
return method(*args, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tweepy\api.py", line 913, in create_favorite
), id=id, **kwargs
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tweepy\api.py", line 257, in request
raise Unauthorized(resp)
tweepy.errors.Unauthorized: 401 Unauthorized
PS C:\Users\User\Desktop\VScode\Python\FibraBot_home>
Any ideas?
If you’re using a method that performs an action on behalf of the authenticating user, e.g. API.update_status(), make sure your app has the write permission.
After giving it the write permission, make sure to regenerate and use new credentials to utilize it.
https://tweepy.readthedocs.io/en/v4.8.0/faq.html#why-am-i-encountering-a-401-unauthorized-error-with-api-or-403-forbidden-error-with-client

raise SlackLoginError(reply=reply) slackclient.server.SlackLoginError

Running the below small script passing OAuth Access Token as a token here :
from slackclient import SlackClient
import os
token = "*********"
sc = SlackClient(token)
print (sc.api_call("api.test"))
if sc.rtm_connect():
print("Starter Bot connected and running!")
GETTING BELOW ERROR
Failed RTM connect
Traceback (most recent call last):
File "C:\Users\320055379\AppData\Local\Programs\Python\Python38-32\lib\site-packages\slackclient\client.py", line 140, in rtm_connect
self.server.rtm_connect(use_rtm_start=with_team_state, **kwargs)
File "C:\Users\320055379\AppData\Local\Programs\Python\Python38-32\lib\site-packages\slackclient\server.py", line 168, in rtm_connect
raise SlackLoginError(reply=reply)
slackclient.server.SlackLoginError
the new granual scope does not support rtm anymore, you can try this link to create a classic bot https://api.slack.com/rtm#create_a_classic_slack_app

Instagram API Python error

I'm trying to familiarize with the library python-instagram.
I've done this code:
from instagram.client import InstagramAPI
clientid = '***'
clientsecret = '***'
api = InstagramAPI(client_id=clientid, client_secret=clientsecret)
tag_name = raw_input("Write the word that you want")
filtered_media = api.tag_recent_media(count=20, max_id=1, tag_name=tag_name)
for media in filtered_media:
print media.images['standard_resolution'].url
and I get the following error using the command line (I have a mac):
Traceback (most recent call last):
File "test.py", line 7, in <module>
filtered_media = api.tag_recent_media(count=20, max_id=1, tag_name=tag_name)
File "build/bdist.macosx-10.6-intel/egg/instagram/bind.py", line 197, in _call
File "build/bdist.macosx-10.6-intel/egg/instagram/bind.py", line 189, in execute
File "build/bdist.macosx-10.6-intel/egg/instagram/bind.py", line 163, in _do_api_request
instagram.bind.InstagramAPIError: (400) OAuthAccessTokenException-The access_token provided is invalid.
Someone knows what is happen? THANKS
I would suggest you to take a look at this sample app . You will get to know how to use python-instagram library.
In your code , You are passing client Id in InstagramAPI(). But as per their sample app required argument is access_token.
code snippet from sample_app.py
api = client.InstagramAPI(access_token=access_token, client_secret=CONFIG['client_secret'])
tag_search, next_tag = api.tag_search(q="backclimateaction")
tag_recent_media, next = api.tag_recent_media(tag_name=tag_search[0].name)
To get tag_search result you must have access_token. you can read this documentation to learn how to generate access token from your app.

python twitter api getting status

I am trying to get a recent status of a twitter user. I type in the following:
>>> from twitter import *
>>> t = Twitter(auth=OAuth(...))
>>> t.statuses.friends_timeline(id="StephenAtHome")
I get the following error at the last line:
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
t.statuses.friends_timeline(id="StephenAtHome")
File "twitter\api.py", line 204, in __call__
return self._handle_response(req, uri, arg_data, _timeout)
File "twitter\api.py", line 235, in _handle_response
raise TwitterHTTPError(e, uri, self.format, arg_data)
TwitterHTTPError: Twitter sent status 404 for URL: 1.1/statuses/friends_timeline/StephenAtHome.json using parameters (oauth_consumer_key=i1xQ3YKmmUI9pKlYDmSPeA&oauth_nonce=12051576929978547960&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1371245218&oauth_token=1517563807-75iFGXWHxMvzzsqrIs5W4tCb4OwFG4eisnDYRst&oauth_version=1.0&oauth_signature=m0LDp%2FdkJLMr3sHPnFQkLKlDTrE%3D)
details: {"errors":[{"message":"Sorry, that page does not exist","code":34}]}
How do I fix this error. I know that the page exists
The problem is that twitter API was upgraded to 1.1 version and friends_timeline was deprecated (see docs). Use home_timeline instead (user_timeline should work but doesn't):
t.statuses.home_timeline(user_id="gvanrossum")
Hope that helps.

Unable to upgrade YouTube session token without logging into Google Accounts user API

I am having trouble upgrading my session token in google app engine if my user is not logged into my application using the google accounts user api. If the user is currently logged in then it functions perfectly.
If not then i am getting this error:
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 511, in __call__
handler.get(*groups)
File "/base/data/home/apps/5th-anniversary/1.341853888797531127/main.py", line 78, in get
u.upgradeToken(self)
File "/base/data/home/apps/5th-anniversary/1.341853888797531127/upload.py", line 47, in upgradeToken
client.UpgradeToSessionToken()
File "/base/data/home/apps/5th-anniversary/1.341853888797531127/gdata/service.py", line 903, in UpgradeToSessionToken
raise NonAuthSubToken
NonAuthSubToken
What are my best options here? I do not want the user to have to log into the google accounts api and then the youtube site to upload a video.
here is my method for updating the token:
def upgradeToken(data,self):
get = self.request.GET
authsub_token = get['token']
gdata.alt.appengine.run_on_appengine(client)
client.SetAuthSubToken(authsub_token)
client.UpgradeToSessionToken()
client is simply client = gdata.youtube.service.YouTubeService()
pretty sure i'm missing something on the authentication side but i can't seem to see what, thanks!
I solved this by using:
client.UpgradeToSessionToken(gdata.auth.extract_auth_sub_token_from_url(self.request.url))
but this raised another issue when building the upload form with
GetFormUploadToken
i receive:
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 513, in __call__
handler.post(*groups)
File "/base/data/home/apps/5th-anniversary/1.341859541699944556/upload.py", line 106, in post
form = u.getUploadForm(self,title,description,keywords)
File "/base/data/home/apps/5th-anniversary/1.341859541699944556/upload.py", line 65, in getUploadForm
response = client.GetFormUploadToken(video_entry,'http://gdata.youtube.com/action/GetUploadToken')
File "/base/data/home/apps/5th-anniversary/1.341859541699944556/gdata/youtube/service.py", line 716, in GetFormUploadToken
raise YouTubeError(e.args[0])
YouTubeError: {'status': 401L, 'body': '<HTML>\n<HEAD>\n<TITLE>User authentication required.</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>User authentication required.</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>\n', 'reason': ''}
Try this:
new_token = client.UpgradeToOAuthAccessToken(
gdata.auth.extract_auth_sub_token_from_url(self.request.url)
client.SetOAuthToken(new_token)
client.GetFormUploadToken(my_video_entry)

Categories