1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GAEで"TypeError: must be _socket.socket, not socket"が出た時の対応

Posted at

概要

Google App Engine(GAE)でtwitter OAuthの機能を使いたくて、requests_oauthlibをいれて動かそうとしたが、うまくいかなかったのでそのメモ

状況・対策

ssl

以下のようなエラーが出る

error.log
Can't connect to HTTPS URL because the SSL module is not available

以下のようにsslモジュールを取り込む

app.yaml
libraries:
- name: ssl
  version: latest

socket

sslモジュールを取り込むと次は以下のようなエラーが出る。実際に試してはないが、これは本番環境では起こらないらしい。

error.log
must be _socket.socket, not socket

以下のようにsandbox.pyの_WHITE_LIST_C_MODULESに_ssl&_socketを追加

sandbox.py.diff
$ diff /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py_orig
912,913d911
<     '_ssl',
<     '_socket',

python標準のsocket.pyをGAEのsocket.pyに上書きする

$ cp /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/dist27/socket.py /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/dist27/socket.py_orig

$ cp /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/dist27/socket.py

requestsモジュールを入れ直す

$ pip uninstall requests
$ pip install requests==2.3

これでうごくようになった。

参考

http://tsuboi-sj.hatenablog.com/entry/2015/05/29/164743
https://stackoverflow.com/questions/16192916/importerror-no-module-named-ssl-with-dev-appserver-py-from-google-app-engine/16937668#16937668

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?