0

For some reason I'm unable to use the socket library completely in webapp2. On printing the dir contents of the library, I get the following:

[
 'AF_INET', 'SOCK_DGRAM', 'SOCK_STREAM', '_GLOBAL_DEFAULT_TIMEOUT',
 '__all__', '__builtins__', '__doc__', '__file__', '__loader__', '__name__',
 '__package__', '_fileobject', 'error', 'gaierror', 'getdefaulttimeout',
 'herror', 'setdefaulttimeout', 'ssl', 'timeout'
]

As you can see, this is not the complete socket library(it also lacks the socket() constructor). Why is this happening and how can I fix it?

Likhit
  • 799
  • 2
  • 6
  • 18
  • Are you using webapp2 on appengine? Using sockets in appengine is not allowed. See: https://developers.google.com/appengine/docs/python/runtime#The_Sandbox – Hans Then Sep 16 '12 at 08:34
  • You may be interested in this App Engine Trusted Testers program: https://groups.google.com/group/google-appengine/browse_thread/thread/9b5c7ab0386ac75a/55fd1147fe9e2d5c – Amy U. Sep 17 '12 at 07:34

2 Answers2

2

Because opening a socket is explicitly forbidden in AppEngine.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • I looked for that before posting the question. But I found other code snippets on stackoverflow using sockets. Eg:- http://stackoverflow.com/questions/11274596/import-error-when-building-python-using-py2exe http://stackoverflow.com/questions/8470733/how-can-i-handle-static-files-with-python-webapp2-in-heroku – Likhit Sep 16 '12 at 08:27
  • Never mind. I didn't realize the difference between webapp2 and appengine. Sorry. – Likhit Sep 16 '12 at 09:01
1

Good news! Google recently released a sockets API for app engine, documentation here:

https://developers.google.com/appengine/docs/python/sockets/

It is still in a preview release (as of Mar. 2014) and it comes with its own host of limitations, but it should be able to handle many situations.

speedplane
  • 15,673
  • 16
  • 86
  • 138