While True Error in Tweepy while Tweeting in Python - python

Everyone. Today, I was creating a Twitter Bot in Python using the tweepy module, which works perfectly. I've observed that when I use a While True command to tweet anything, it will Tweet it at first, so show me an error here it is below.
Response(data={'id': '1522239311277486080', 'text': 'Alas, after a certain age every man is responsible for his face.-Albert Camus'}, includes={}, errors=[], meta={})
Traceback (most recent call last):
File "C:\Users\varni\PycharmProjects\Twitter_Bot Version 1\main.py", line 13, in <module>
response = client.create_tweet(text=Quotes.Quotes_Random)
File "C:\Users\varni\PycharmProjects\Twitter_Bot Version 1\venv\lib\site-packages\tweepy\client.py", line 824, in create_tweet
return self._make_request(
File "C:\Users\varni\PycharmProjects\Twitter_Bot Version 1\venv\lib\site-packages\tweepy\client.py", line 126, in _make_request
response = self.request(method, route, params=request_params,
File "C:\Users\varni\PycharmProjects\Twitter_Bot Version 1\venv\lib\site-packages\tweepy\client.py", line 99, in request
raise Forbidden(response)
tweepy.errors.Forbidden: 403 Forbidden
And here is the code-
import config
import tweepy
import Quotes
import time
client = tweepy.Client(consumer_key=config.API_KEY,
consumer_secret=config.API_SECRET,
access_token=config.ACCESS_TOKEN,
access_token_secret=config.ACCESS_TOKEN_SECRET)
while True:
# time.sleep(600)
response = client.create_tweet(text=Quotes.Quotes_Random)
print(response)
is there way to fix this error?

You're likely encountering this because you can't Tweet the exact same text you've already recently Tweeted.

Related

python skype groupchat GET response error

I'm getting error in trying to communicate in a group chat via skype.
Traceback (most recent call last):
File "C:\Program Files\Python\Python38-32\ga.py", line 12, in
skc.recent()
File "C:\Program Files\Python\Python38-32\lib\site-packages\skpy\chat.py", line 452, in recent
info = self.skype.conn("GET", "{0}/threads/{1}".format(self.skype.conn.msgsHost, json.get("id")),
File "C:\Program Files\Python\Python38-32\lib\site-packages\skpy\conn.py", line 219, in call
raise SkypeApiException("{0} response from {1} {2}".format(resp.status_code, method, url), resp)
skpy.core.SkypeApiException: ('404 response from GET https://azwus1-client-s.gateway.messenger.live.com/v1/threads/19:*********************', )
[Finished in 7.483s]
I'm just trying to test to send a simple chat to a groupchat but I'm not sure what is causing this error.
currently using this code
ch = sk.chats["19:***********************#thread.skype"] //due to privacy issue, i cant display the id
ch.sendMsg("testing")
whereas if I use the code this way for creating a new conversation,
ch = sk.contacts["live#123"].chat
ch.sendMsg("testing")
it will work.
Can someone enlighten me what is the issue with it? really appreciate a lot.

hubspot3 client and "too many retries" error

I'm trying to pull the details for a contact from hubspot using the recipient's email. I'm using the python3 client "hubspot3" (https://github.com/jpetrucciani/hubspot3).
Here's the code I'm submitting:
import requests
from hubspot3.contacts import ContactsClient
API_KEY=[myapikey]
client=ContactsClient(api_key=API_KEY,debug=True)
email='mytest#gmail.com'
client.get_contact_by_email(email)
The response:
WARNING:root:Too many retries for /contacts/v1/contact/email/nwnippy27+cb1#gmail.com/profile?hapikey=[myapikey]
Traceback (most recent call last):
File "hubspot_api_test.py", line 11, in <module>
client.get_contact_by_email(email)
File "/opt/virtual_env/hubspot-test/lib/python3.7/site-packages/hubspot3/contacts.py", line 38, in get_contact_by_email
"contact/email/{email}/profile".format(email=email), method="GET", **options
File "/opt/virtual_env/hubspot-test/lib/python3.7/site-packages/hubspot3/base.py", line 339, in _call
**options
File "/opt/virtual_env/hubspot-test/lib/python3.7/site-packages/hubspot3/base.py", line 245, in _call_raw
result = self._execute_request_raw(connection, request_info)
File "/opt/virtual_env/hubspot-test/lib/python3.7/site-packages/hubspot3/base.py", line 162, in _execute_request_raw
raise HubspotNotFound(result, request)
hubspot3.error.HubspotNotFound:
Hubspot Error
I'm reading this error as saying that the email address can't be found. Is that correct? If not, I appreciate any intel on the cause and solution.
OK ... so not super useful, but it turned out that this is just the error message you get when the email doesn't exist. After a few tries it gives up, which is why you get the "too many retries" error.

Can't run simple python reddit program?

Here is the python reddit program, the code is 100% fine. It's from a tutorial website.
#!/usr/bin/python
import praw
reddit = praw.Reddit('bot1')
subreddit = reddit.subreddit("learnpython")
for submission in subreddit.hot(limit=5):
print("Title: ", submission.title)
print("Text: ", submission.selftext)
print("Score: ", submission.score)
print("---------------------------------\n")
When I run it I get this error.
Traceback (most recent call last):
File "Top3Links.py", line 4, in <module>
reddit = praw.Reddit('bot1')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/praw/reddit.py", line 105, in __init__
**config_settings)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/praw/config.py", line 64, in __init__
self.custom = dict(Config.CONFIG.items(site_name), **settings)
File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ConfigParser.py", line 347, in items
raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'bot1'
Eric-MacBook-Pro:PythonRedditBot Eric$
It maybe has something to do with installing python 3.5 any help would be amazing.
You appear to be missing a config file for this module. Check out the documentation:
https://praw.readthedocs.io/en/latest/getting_started/configuration/prawini.html
According to the documentation, you need a praw.ini file, containing a section like this:
[bot1]
client_id=Y4PJOclpDQy3xZ
client_secret=UkGLTe6oqsMk5nHCJTHLrwgvHpr
password=pni9ubeht4wd50gk
username=fakebot1
The source may also be informative: https://github.com/praw-dev/praw/blob/master/praw/reddit.py#L79

API Python smartsheet can't connect with SDK

I'm pretty new to Python and I'm trying to connect to smartsheet with API.
I have ran "pip install smartsheet-python-sdk" and it installed smartsheet as I can find it under "lib"
This is code I have found and supposed to work(I replaced the token with the token)
# Import.
import smartsheet
# Instantiate smartsheet and specify access token value.
smartsheet = smartsheet.Smartsheet('Token_here')
# Get all columns.
action = smartsheet.Sheets.get_columns('Template for Bram', include_all=True)
columns = action.data
# For each column, print Id and Title.
for col in columns:
print(col.id)
print(col.title)
print('')
It shows this error:
Traceback (most recent call last):
File "C:\Users\bram\Desktop\smartsheet.py", line 2, in <module>
import smartsheet
File "C:\Users\bram\Desktop\smartsheet.py", line 5, in <module>
smartsheet = smartsheet.Smartsheet('token_here')
AttributeError: 'module' object has no attribute 'Smartsheet'
Now I'm not sure what my next step is. I think I have followed all of the appropriate steps. When I run import smartsheet by itself it won't error out.
What am I doing wrong?
Thank you
Update***
After using the code from the github page and implementing my token and sheet id I get this error:
Traceback (most recent call last):
File "C:\Users\bvanhout\Desktop\test23.py", line 58, in <module>
sheet = ss.Sheets.get_sheet(sheet_id)
File "C:\Python27\lib\site-packages\smartsheet\sheets.py", line 460, in get_sheet
response = self._base.request(prepped_request, expected, _op)
File "C:\Python27\lib\site-packages\smartsheet\smartsheet.py", line 178, in request
res = self.request_with_retry(prepped_request, operation)
File "C:\Python27\lib\site-packages\smartsheet\smartsheet.py", line 242, in request_with_retry
return self._request(prepped_request, operation)
File "C:\Python27\lib\site-packages\smartsheet\smartsheet.py", line 210, in _request
raise UnexpectedRequestError(rex.request, rex.response)
UnexpectedRequestError: (<PreparedRequest [GET]>, None)
# TODO: Update this with the ID of your sheet to update
sheet_id = 48568543424234
I printed ss and ss.Sheets and both do not reflect the actual token or sheet_id
>>> print (ss.Sheets)
<smartsheet.sheets.Sheets object at 0x0000000003874438>
I suspect the problem is that you are using a local variable with the same name as the module ('smartsheet')
Please take a look at the sample here: https://github.com/smartsheet-samples/python-read-write-sheet

Traceback when updating status on twitter via Tweepy

I've been trying to post the readings from my Rpi on Twitter using tweepy, but first I wanted to check if tweepy was working properly, but it's not.
I installed the packages properly, but when I'm trying to run a simple code to post something, I got an error (Yes, I already created an app and have the 4 credentials).
The code I'm trying to run:
import tweepy
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
single_tweet = 'hello world'
api.update_status(single_tweet)
print "successfully Updated"
I got this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.linux-armv6l/egg/tweepy/api.py", line 193, in update_status
File "build/bdist.linux-armv6l/egg/tweepy/binder.py", line 239, in _call
File "build/bdist.linux-armv6l/egg/tweepy/binder.py", line 223, in execute
tweepy.error.TweepError: [{u'message': u'media_ids parameter is invalid.', u'code': 44}]
I'm runing the python code that is in the tweepy folder "oauth.py" (adding it my credentials)
$ sudo python oauth.py
RapiCARA
Traceback (most recent call last):
File "oauth.py", line 34, in <module>
api.update_status(' Hello world ')
File "build/bdist.linux-armv6l/egg/tweepy/api.py", line 193, in update_status
File "build/bdist.linux-armv6l/egg/tweepy/binder.py", line 239, in _call
File "build/bdist.linux-armv6l/egg/tweepy/binder.py", line 223, in execute
tweepy.error.TweepError: [{u'message': u'media_ids parameter is invalid.', u'code': 44}]
The code in that file, you can find it in its origial source: Tweepy in GITHUB
Any help/advice please?
The first positional argument to the update_status() method is interpreted as the media_ids parameter. You need to explicitly name your status parameter to avoid this:
api.update_status(status=single_tweet)
This is a recent change in Tweepy and it looks like their documentation hasn't been updated yet to reflect this.
The different signature has been reported as a bug for the project.
The bug was fixed in August 2015; version 3.5 or newer of Tweepy once again treat the first positional argument as the status parameter.

Categories

Resources