HttpError 502 with Google Wave Active Robot API fetch_wavelet() - python

I am trying to use the Google Wave Active Robot API fetch_wavelet() and I get an HTTP 502 error
example:
from waveapi import robot
import passwords
robot = robot.Robot('gae-run', 'http://images.com/fake-image.jpg')
robot.setup_oauth(passwords.CONSUMER_KEY, passwords.CONSUMER_SECRET, server_rpc_base='http://www-opensocial.googleusercontent.com/api/rpc')
wavelet = robot.fetch_wavelet('googlewave.com!w+dtuZi6t3C','googlewave.com!conv+root')
robot.submit(wavelet)
self.response.out.write(wavelet.creator)
But the error I get is this:
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/clstff/gae-run.342467577023864664/main.py", line 23, in get
robot.submit(wavelet)
File "/base/data/home/apps/clstff/gae-run.342467577023864664/waveapi/robot.py", line 486, in submit
res = self.make_rpc(pending)
File "/base/data/home/apps/clstff/gae-run.342467577023864664/waveapi/robot.py", line 251, in make_rpc
raise IOError('HttpError ' + str(code))
IOError: HttpError 502
Any ideas?
Edit:
When clstff#appspot.com is not a member of the wave I get the correct error message
Error: RPC Error500: internalError: clstff#appspot.com is not a participant of wave id: [WaveId:googlewave.com!w+Pq1HgvssD] wavelet id: [WaveletId:googlewave.com!conv+root]. Unable to apply operation: {'method':'robot.fetchWave','id':'655720','waveId':'googlewave.com!w+Pq1HgvssD','waveletId':'googlewave.com!conv+root','blipId':'null','parameters':{}}
But when clstff#appsot.com is a member of the wave I get the http 502 error.
IOError: HttpError 502

Joe Gregorio answered my question on the Google Wave API Google group
Did you make any changes to the
wavelet before submitting it? I think
there was an old bug where sending in
an empty change would cause a 502,
this might be a regression in that
behavior.
If I removed the robot.submit(wavelet) line, it worked!

Related

Spotipy throws 404 when retrieving song data

EDIT 2: As #ximzend said, spotipy has moved to playlist_items instead of playlist_tracks
EDIT 1: In the process of moving to a curses interface, I changed the progress bar to a tqdm one (rather than rich), and that seemed to solve my problem. I did also upgrade spotipy (after it started working) but no change was needed in the API code ¯( ツ )/¯ so idk if rich was breaking the API req somehow or whatever
Thought I would put this here to help anyone in the future ツ
Spotipy throws this error when trying to retrieve data about tracks in a playlist
requests.exceptions.HTTPError: 404 Client Error: Not Found for url:
The error is thrown on the line below, specifically the self.sp.playlist_tracks(playlist_uri)['items'] part (The progress.track is a progress bar for the loop from rich)
for song in progress.track(self.sp.playlist_tracks(playlist_uri)['items'], description='Listing songs...'):
Full traceback is:
HTTP Error for GET to https://api.spotify.com/v1/playlists/4wi8hpuh4oyjtivbzk3k9n/tracks with Params: {'limit': 100, 'offset': 0, 'fields': None, 'market': None, 'additional_types': 'track'} returned 404 due to Not found.
Traceback (most recent call last):
File "T:\projects\youtusic\youtusic-env\Lib\site-packages\spotipy\client.py", line 245, in _internal_call
response.raise_for_status()
File "T:\projects\youtusic\youtusic-env\Lib\site-packages\requests\models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.spotify.com/v1/playlists/4wi8hpuh4oyjtivbzk3k9n/tracks?limit=100&offset=0&additional_types=track
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "t:\projects\youtusic\main.py", line 132, in <module>
main()
File "t:\projects\youtusic\main.py", line 119, in main
track_list = obj.sp_get_tracks(playlist_uri)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "t:\projects\youtusic\youtusic.py", line 104, in sp_get_tracks
for song in progress.track(self.sp.playlist_tracks(playlist_uri)['items'], description='Listing songs...'):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "T:\projects\youtusic\youtusic-env\Lib\site-packages\spotipy\client.py", line 657, in playlist_tracks
return self.playlist_items(playlist_id, fields, limit, offset,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "T:\projects\youtusic\youtusic-env\Lib\site-packages\spotipy\client.py", line 681, in playlist_items
return self._get(
^^^^^^^^^^
File "T:\projects\youtusic\youtusic-env\Lib\site-packages\spotipy\client.py", line 297, in _get
return self._internal_call("GET", url, payload, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "T:\projects\youtusic\youtusic-env\Lib\site-packages\spotipy\client.py", line 267, in _internal_call
raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/playlists/4wi8hpuh4oyjtivbzk3k9n/tracks?limit=100&offset=0&additional_types=track:
Not found., reason: None
The code I was using was as follows:
def sp_get_tracks(self, playlist_link: str) -> list:
'''
Uses [spotipy](https://pypi.org/project/spotipy/) to retrieve
a list of songs in the playlist provided. Returns a list to be
used with `grab_yt_links`
'''
playlist_uri = playlist_link.split('/')[-1].split('?')[0]
song_titles = []
for song in progress.track(self.sp.playlist_tracks(playlist_uri)['items'], description='Listing songs...'):
track_name: str = song['track']['name']
artist_name: str = song['track']['artists'][0]['name']
track_name = track_name.replace(' ', '+')
artist_name = artist_name.replace(' ', '+')
song_titles.append(f'{artist_name}+{track_name}')
return song_titles
It should returns a list of all the songs (and artists) in the playlist. (The progress.track is a progress bar for the loop from rich). The 404 confuses me because my network connection is fine and I am able to perform Google searches etc
Additionally, the playlist only has 19 songs in so should be resticted by the limits I have read elsewhere
You get this error, because Spotify made a code breaking change to its API.
SpotiPy has fixed this issue by releasing an upgrade.
To install this upgrade, open a command prompt and run pip install spotipy --upgrade.
After the upgrade, you need to use playlist_items(playlist_id, fields=None, limit=100, offset=0, market=None, additional_types=('track', 'episode')). playlist_tracks is deprecated.

Catching Firebase 504 gateway timeout

I'm building a simple IOT device (with a Raspberry Pi Zero) which pulls data from Firebase Realtime Database every 1 second and checks for updates.
However, after a certain time (not sure exactly how much but somewhere between 1 hour and 3 hours) the program exits with a 504 Server Error: Gateway Time-out message.
I couldn't understand exactly why this is happening, I tried to recreate this error by disconnecting the Pi from the internet and I did not get this message. Instead, the program simply paused in a ref.get() line and automatically resumed running once the connection was back.
This device is meant to be always on, so ideally if I get some kind of error, I would like to restart the program / reinitiate the connection / reboot the Pi. Is there a way to achieve something like this?
It seems like the message is actually generated by the firebase_admin package.
Here is the error message:
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/db.py", line 944, in request
return super(_Client, self).request(method, url, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/_http_client.py", line 105, in request
resp.raise_for_status()
File "/usr/lib/python3/dist-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 504 Server Error: Gateway Time-out for url: https://someFirebaseProject.firebaseio.com/someRef/subSomeRef/payload.json
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Desktop/project/main.py", line 94, in <module>
lastUpdate = ref.get()['lastUpdate']
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/db.py", line 223, in get
return self._client.body('get', self._add_suffix(), params=params)
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/_http_client.py", line 117, in body
resp = self.request(method, url, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/db.py", line 946, in request
raise _Client.handle_rtdb_error(error)
firebase_admin.exceptions.UnknownError: Internal server error.
>>>
To reboot the whole Raspberry Pi, you can just run a shell command:
import os
os.system("sudo reboot")
I've had this problem too and usually feel safer with that, but there's obvious downsides. I'd try resetting the wifi connection or network interface in a similar way

Twilio - Python : NameError from Udacity Tutorial

Hoping I could get input on what this error means and what I have to do to fix it. Thanks.
This is the error that appears:
Traceback (most recent call last):
File "/Users/davidongchoco/Desktop/Python Programming/send_text.py", line 11, in <module>
from_="+13348331130") # Replace with your Twilio number
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio/rest/resources/sms_messages.py", line 167, in create
return self.create_instance(kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio/rest/resources/base.py", line 365, in create_instance
data=transform_params(body))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio/rest/resources/base.py", line 200, in request
resp = make_twilio_request(method, uri, auth=self.auth, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio/rest/resources/base.py", line 164, in make_twilio_request
uri=resp.url, msg=message, code=code)
TwilioRestException:
[31m[49mHTTP Error[0m [37m[49mYour request was:[0m
[36m[49mPOST https://api.twilio.com/2010-04-01/Accounts/ACf37c4004688accd3f501ab2a2c9dc7e1/SMS/Messages.json[0m
[37m[49mTwilio returned the following information:[0m
[34m[49mPermission to send an SMS has not been enabled for the region indicated by the 'To' number: +639228902063.[0m
[37m[49mMore information may be available here:[0m
[34m[49mhttps://www.twilio.com/docs/errors/21408[0m
>>>
Twilio developer evangelist here.
The error has delivered a message to you that says:
Permission to send an SMS has not been enabled for the region indicated by the 'To' number: +639228902063.
More information may be available here:
https://www.twilio.com/docs/errors/21408
If you follow that link, it tells you that you need to enable some global permissions on your account. You can do that here: https://www.twilio.com/user/account/settings/international/sms
It looks as though you are trying to send to a number from the Philippines, so make sure that check box is ticked.
Good luck with the Udacity course!

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.

gdata internal error

Since yesterday a working Python gdata program has stopped working after I changed the IP address used.
I receive the following stack trace:
Traceback (most recent call last):
File "C:\prod\googleSite\googleSite2.py", line 23, in
feed = client.GetContentFeed()
File "C:\Python27\lib\site-packages\gdata\sites\client.py", line 155, in get_c
ontent_feed
auth_token=auth_token, **kwargs)
File "C:\Python27\lib\site-packages\gdata\client.py", line 635, in get_feed
**kwargs)
File "C:\Python27\lib\site-packages\gdata\client.py", line 320, in request
RequestError)
gdata.client.RequestError: Server responded with: 500, Internal Error
The code is as follow:
import gdata.sites.client
import gdata.sites.data
client = gdata.sites.client.SitesClient(source='xxx', site='yyy')
client.ssl = True # Force API requests through HTTPS
client.ClientLogin('user#googlemail.com', 'password', client.source);
feed = client.GetContentFeed();
Update:
The issue fixes itself after an hour - is there any kind of commit or logout to avoid this?
Since you're not passing anything in GetContentFeed, it's using CONTENT_FEED_TEMPLATE % (self.domain, self.site) as the URI. I'm not sure if the IP change had an impact on what the self.domain/self.site values should be, but it might be worth checking those out.

Categories