pyfoo / python-twitter

Automatically exported from code.google.com/p/python-twitter
Apache License 2.0
0 stars 0 forks source link

Won't work on google app engine #59

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. wget twitter.py into your GAE directory
2. load it
3. instantiate an API instance

What is the expected output? What do you see instead?
I'd like this to work but it throws an error because the GAE implementation
of the os module doesn't have os.getlogin()

What version of the product are you using? On what operating system?
Mas OS X, latest GAE

Please provide any additional information below.

It does look like it's possible to do "SetCache(None)" but it seems as
though you can call this only after you have an API instance, and since the
API initialization itself is throwing the exception then this doesn't work.

Here's my quick patch;

loki:reviewtwit wjhuie$ diff -u twitter.py jay_twitter.py 
--- twitter.py  2009-03-31 11:52:16.000000000 -0400
+++ jay_twitter.py  2009-03-31 15:50:00.000000000 -0400
@@ -1290,7 +1290,12 @@
       input_encoding: The encoding used to encode input strings. [optional]
       request_header: A dictionary of additional HTTP request headers.
[optional]
     '''
-    self._cache = _FileCache()
+    try:
+        import google.appengine.api
+        self._cache = None
+    except ImportError:
+        self._cache = _FileCache()
+
     self._urllib = urllib2
     self._cache_timeout = Api.DEFAULT_CACHE_TIMEOUT
     self._InitializeRequestHeaders(request_headers)

Ideally, I'd like to set the cache to something that would work with Google
App Engine but I'm not sure what would be best (memcache, datastore, etc.)
given the potential security issue if sessions are reused.

So I'm off to finish my program (w/o caching) first and I'll think on this.

Original issue reported on code.google.com by wjh...@gmail.com on 31 Mar 2009 at 7:49

GoogleCodeExporter commented 9 years ago
Traceback (most recent call last):
  File
"/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-de
fault.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__i
nit__.py",
line 498, in __call__
    handler.get(*groups)
  File "/Users/samj/Development/Internet/flitter/trunk/main.py", line 28, in get
    api = twitter.Api(username="abc", password="xyz")
  File "./python-twitter/twitter.py", line 1293, in __init__
    self._cache = _FileCache()
  File "./python-twitter/twitter.py", line 2046, in __init__
    self._InitializeRootDirectory(root_directory)
  File "./python-twitter/twitter.py", line 2106, in _InitializeRootDirectory
    root_directory = self._GetTmpCachePath()
  File "./python-twitter/twitter.py", line 2100, in _GetTmpCachePath
    username = self._GetUsername()
  File "./python-twitter/twitter.py", line 2094, in _GetUsername
    os.getlogin() or \
AttributeError: 'module' object has no attribute 'getlogin'

You can easy enough ignore the AttributeError and pass back 'nobody' but I'm 
not sure
of the implications for caching et al.

Sam

Original comment by s...@samj.net on 12 Apr 2009 at 1:03

Attachments:

GoogleCodeExporter commented 9 years ago
Yea, I ended up having to go with a simplified implementation since 
python-twitter
uses a lot more modules then are included in GAE by default. Still, might be a 
nice
goal to shoot for at some point.

Original comment by wjh...@gmail.com on 12 Apr 2009 at 7:31

GoogleCodeExporter commented 9 years ago
setting cache=None in the twitter.Api constructor avoids this error.

this is my quick fix until I implement a memcache solution for appengine.

Original comment by mhawthorne on 10 May 2010 at 12:48

GoogleCodeExporter commented 9 years ago
marking as fixed because you can do what comment 3 above suggests to avoid the 
GAE issue

Original comment by bear42 on 18 Aug 2010 at 7:08