Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSError thrown from _GetUsername when accessed from non tty terminal #16

Open
GoogleCodeExporter opened this issue Nov 19, 2015 · 17 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Utilise python-twitter from a non tty terminal (e.g. from Asterisk in
this case)
2.
3.

What is the expected output? What do you see instead?
  File "/usr/lib/python2.5/site-packages/twitter.py", line 1477, in __init__
    self._InitializeRootDirectory(root_directory)
  File "/usr/lib/python2.5/site-packages/twitter.py", line 1537, in
_InitializeRootDirectory
    root_directory = self._GetTmpCachePath()
  File "/usr/lib/python2.5/site-packages/twitter.py", line 1531, in
_GetTmpCachePath
    username = self._GetUsername()
  File "/usr/lib/python2.5/site-packages/twitter.py", line 1525, in
_GetUsername
    os.getlogin() or \
OSError: [Errno 25] Inappropriate ioctl for device
Twitter Failed

What version of the product are you using? On what operating system?
python-twitter Revision 116
Python 2.5.1 (r251:54863, Mar  7 2008, 03:39:23) 
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2


Please provide any additional information below.

 I have been able to work around this issue by catching the OSError
exception. Patch attached. 

Original issue reported on code.google.com by glen.tre...@gmail.com on 20 May 2008 at 12:37

Attachments:

@GoogleCodeExporter
Copy link
Author

This also is a problem with the os.getlogin() call from _GetUsername. This fails
(throws an OSError) if there is no TTY attached.

VERSION:
The 0.5 download from the frontpage.

EXCEPTION:
twitter.py:1451 __init__
twitter.py:1508 _InitializeRootDirectory
twitter.py:1502 _GetTmpCachePath
twitter.py:1498 _GetUsername
<type 'exceptions.OSError'>: [Errno 2] No such file or directory

Original comment by tehm...@gmail.com on 10 Jun 2008 at 8:48

@GoogleCodeExporter
Copy link
Author

Confirming this issue. I get the same error when trying to use it in Google App
Engine environment. Here is the code:

{{{
import wsgiref.handlers
from google.appengine.ext import webapp
import simplejson
import twitter

class MainHandler(webapp.RequestHandler):

  def get(self):
    pass
    api = twitter.Api()
    statuses = api.GetPublicTimeline()


def main():
  application = webapp.WSGIApplication([('/', MainHandler)], debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == '__main__':
  main()
}}}

This throws the following error:

{{{
Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp
\__init__.py", line 499, in __call__
    handler.get(*groups)
  File "C:\Program Files\Google\google_appengine\is-twitter-happy\main.py", line 29,
in get
    api = twitter.Api()
  File "C:\Python25\lib\site-packages\python_twitter-0.5-py2.5.egg\twitter.py", line
900, in __init__
    self._cache = _FileCache()
  File "C:\Python25\lib\site-packages\python_twitter-0.5-py2.5.egg\twitter.py", line
1451, in __init__
    self._InitializeRootDirectory(root_directory)
  File "C:\Python25\lib\site-packages\python_twitter-0.5-py2.5.egg\twitter.py", line
1508, in _InitializeRootDirectory
    root_directory = self._GetTmpCachePath()
  File "C:\Python25\lib\site-packages\python_twitter-0.5-py2.5.egg\twitter.py", line
1502, in _GetTmpCachePath
    username = self._GetUsername()
  File "C:\Python25\lib\site-packages\python_twitter-0.5-py2.5.egg\twitter.py", line
1498, in _GetUsername
    os.getlogin() or \
AttributeError: 'module' object has no attribute 'getlogin'
}}}

Original comment by maci...@gmail.com on 22 Jun 2008 at 5:16

@GoogleCodeExporter
Copy link
Author

The noTTY.patch is now applied in trunk.  Really sorry for the delay -- I 
didn't see
this issue open.  Thanks so much for the reports and the fix!

Original comment by dclinton on 10 Jul 2008 at 9:45

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

I've just downloaded the most recent version, but seem to have the same problem 
when I 
use it with google appengine? is the noTTY.patch something I have to apply 
manually?

Original comment by sht...@gmail.com on 16 May 2009 at 12:15

@GoogleCodeExporter
Copy link
Author

I think AttributeError needs to be caught as well

Original comment by philgull...@gmail.com on 3 Jan 2010 at 7:33

@GoogleCodeExporter
Copy link
Author

this isnt fixed. seeing this issue at my end also.

Original comment by alon.car...@gmail.com on 25 Jun 2010 at 11:39

@GoogleCodeExporter
Copy link
Author

work for me !
Actually I didnt update the twitter.py .
But I manually added the pacth and its working 

Obs: I'm using inside pinax version not updated  + apache + wsgi. 

Original comment by cadu...@gmail.com on 30 Aug 2010 at 6:47

@GoogleCodeExporter
Copy link
Author

I have this issue too

Original comment by Pr.Dor...@gmail.com on 21 Dec 2010 at 5:22

@GoogleCodeExporter
Copy link
Author

Same problem in Google App Engine.

Original comment by Rama...@gmail.com on 23 Feb 2011 at 4:45

@GoogleCodeExporter
Copy link
Author

what version are you using? 0.5 or 0.6 ?

Original comment by bear42 on 23 Feb 2011 at 4:48

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

__version__ = '0.8.1'

Original comment by Rama...@gmail.com on 23 Feb 2011 at 4:50

@GoogleCodeExporter
Copy link
Author

Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3245, in _HandleRequest
    self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3186, in _Dispatch
    base_env_dict=env_dict)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 531, in Dispatch
    base_env_dict=base_env_dict)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2410, in Dispatch
    self._module_dict)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2320, in ExecuteCGI
    reset_modules = exec_script(handler_path, cgi_path, hook)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2216, in ExecuteOrImportScript
    exec module_code in script_module.__dict__
  File "C:\Users\ramayac\Desktop\TrendingSV\main.py", line 31, in <module>
    api = twitter.Api()
  File "C:\Users\ramayac\Desktop\TrendingSV\twitter.py", line 1970, in __init__
    self.SetCache(cache)
  File "C:\Users\ramayac\Desktop\TrendingSV\twitter.py", line 3274, in SetCache
    self._cache = _FileCache()
  File "C:\Users\ramayac\Desktop\TrendingSV\twitter.py", line 3607, in __init__
    self._InitializeRootDirectory(root_directory)
  File "C:\Users\ramayac\Desktop\TrendingSV\twitter.py", line 3667, in _InitializeRootDirectory
    root_directory = self._GetTmpCachePath()
  File "C:\Users\ramayac\Desktop\TrendingSV\twitter.py", line 3661, in _GetTmpCachePath
    username = self._GetUsername()
  File "C:\Users\ramayac\Desktop\TrendingSV\twitter.py", line 3655, in _GetUsername
    os.getlogin() or \
AttributeError: 'module' object has no attribute 'getlogin'

Original comment by Rama...@gmail.com on 23 Feb 2011 at 4:54

@GoogleCodeExporter
Copy link
Author

ouch!

ok, i'll bump that up to the top for this weekend's work - thanks for the report

Original comment by bear42 on 23 Feb 2011 at 4:56

  • Added labels: Priority-Critical
  • Removed labels: Priority-Medium

@GoogleCodeExporter
Copy link
Author

haha, no problem, thanks! :D

Original comment by Rama...@gmail.com on 23 Feb 2011 at 4:57

@GoogleCodeExporter
Copy link
Author

Is there any known work-around for this on AppEngine or is it fixed in a recent 
beta version?

Original comment by staringmonkey on 6 Apr 2011 at 4:12

@GoogleCodeExporter
Copy link
Author

Disregard last, passing cache=None to Api() seems to have gotten around this. 
Thanks!

Original comment by staringmonkey on 6 Apr 2011 at 4:19

@GoogleCodeExporter
Copy link
Author

I still have this problem when running in AppEngine

__version__ = '0.8.2'

Original comment by mare...@gmail.com on 3 Aug 2011 at 10:12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant