Any idea why a twitter python bot on google app engine stopped working?
February 20, 2017 10:08 AM   Subscribe

My twitter bot, running on Google App Engine with python has stopped worked and is producing an error. Is there an easy way to fix this?

The twitter bot counts down the days until the 2018 midterm election. After over a year of happily plugging along, it stopped working on February 11th. I barely know python and twython and google app engine, but I followed a guide to get it set up.

Here is a github with the main files. Here is the error that I am seeing in google app engine. Here is the error text.

Along with the github I posted above, I also have the twython files to make it run, which can be found here (I have the twython, oauthlib, requests, and requests_oauthlib folders uploaded in my Google App Engine).

I'm cautiously optimistic that this is a simple fix, and that there was some recent change to Google App Engine that needs a simple fix on my end. But writing this main file is pushing up to the limit on my python knowledge, so I can't understand what the GAE error is telling me. I haven't made any recent changes on my part. In November, I switched it from counting down the 2016 general election to the 2018 midterm, but that was the last change.

I'm around, if there is anything else from Google App Engine or the files that it would be helpful to upload or answer. Thanks!
posted by andoatnp to Technology (10 answers total)
Just taking a quick look, it's asking for an app attribute so I maybe should have app defined somewhere app = something... maybe something like app = webapp2.WSGIApplication(...)
posted by czytm at 10:37 AM on February 20, 2017

Have any of your keys or secrets expired?
posted by the Real Dan at 11:19 AM on February 20, 2017

I logged into and the Keys and Access Tokens look good.
posted by andoatnp at 11:34 AM on February 20, 2017

Found this in the tutorial on appengine-helloworld-python and maybe it's something that used to be optional that now they're being strict about?

app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)

(in this case MainHandler was the name of the main function...)

posted by one4themoment at 1:44 PM on February 20, 2017

How do I find out what to put for MainHandler?
posted by andoatnp at 2:48 PM on February 20, 2017

You could try this:

Note: I removed a lot of your includes because I don't think you're using them, although you don't have to remove them.

If that doesn't work, you can try changing also changing your app.yaml file to this, specifically the url part to:
- url: /.*
posted by czytm at 2:59 PM on February 20, 2017 [1 favorite]

You are using the google set up, which looks like it requires your 'app' to be a Flask app.

As czytm mentions (and does above) you should probably be able to fix it using something like the example you link to - wrap all of your code (lines 33-47) in a function, then call the function as an app, like the example does in line 65-67.

This is not good flask practice however!
posted by scodger at 6:28 PM on February 20, 2017

I used the suggestion from czytm here and it worked.

All it needed was this at the end "app = webapp2.WSGIApplication(['/', DaysUntill])" and my litlte twitterbot is humming along again.
posted by andoatnp at 5:31 PM on February 22, 2017

The weird thing is that "DaysUntil" isn't a name I'm using anywhere else, so I don't really know *why* it's working.
posted by andoatnp at 5:32 PM on February 22, 2017

What I did in that gist was just put all of your code into a class called DaysUntill with one method get.

What I think the purpose of ['/', DaysUntill], is that it is acting as a router, basically telling your application that "whenever you get a request to the root "/", use this class". And if that request is an http get request, it runs the get method. More on URI routing in webapp2.

In your case, if you didn't implement the class like in the code I posted, it probably still works because all of your code lives outside any class, so it would get executed on any request, or anytime that file is run as a script. So you maybe don't even need that ['/', DaysUntill], but I wouldn't worry about it if it's working.

Disclaimer: I have no experience with webapp2, google app engine, or python, I just took a glance at the documentation and have general web application development experience elsewhere and am applying my general knowledge to this situation, so my explanation could be off.
posted by czytm at 10:53 AM on February 28, 2017

« Older How to wait for something you really need?   |   Refinancing an investment property >50% renter... Newer »
This thread is closed to new comments.