What to do when "Type Error: must be _socket.socket, not socket" appears on GAE

Overview

I wanted to use the function of twitter OAuth on Google App Engine (GAE) and tried to run it with requests_oauthlib, but it didn't work, so that memo

Situation / Countermeasures

ssl I get the following error

error.log


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

Incorporate ssl module as below

app.yaml


libraries:
- name: ssl
  version: latest

socket When I import the ssl module, I get the following error. I haven't actually tried it, but this doesn't seem to happen in a production environment.

error.log


must be _socket.socket, not socket

Add _ssl & _socket to _WHITE_LIST_C_MODULES in sandbox.py as below

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',

Overwrite python standard socket.py with 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

Reinsert the requests module

$ pip uninstall requests
$ pip install requests==2.3

Now it's moving.

reference

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

Recommended Posts

What to do when "Type Error: must be _socket.socket, not socket" appears on GAE
What to do when "TypeError: must be string, not int…" appears when using strptime
What to do when "TypeError: data type not understood" appears in python's numpy.zeros
[Python] Type Error:'WebElement' object is not iterable What to do when an error occurs
What to do when Japanese is not displayed on matplotlib
What to do when python3 type venv does not work well on Raspberry Pi
[virtualbox] What to do when [Could not retrieve mirrorlist] appears when yum update is performed on CentOS7
What to do when pyinstaller: error: argument --add-binary: invalid add_data_or_binary value: appears
[Docker] What to do when error Couldn't find the binary git appears
Notes on what to do when matplotlib scatter () / scatter3d () does not work
What to do if you get "The session could not be opened" when installing CentOS on VirtualBox
[Go 1.13] What to do when unexpected directory layout: appears
[openpyxl] What to do when IllegalCharacterError appears in pandas.DataFrame.to_excel
What to do when raise ValueError, "unsupported hash type"
What to do when is not in the sudoers file.This incident will be reported.
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux
What to do when a Remove Error occurs when updating conda
What to do when an error occurs with import _ssl
What to do when "SSL: CERTIFICATE_VERIFY_FAILED _ssl.c: 1056" appears in Python
OSError: [Errno 40] What to do when Message too long appears
What to do when "Invalid HTTP_HOST header" appears in Django
What to do when Ubuntu crashes
What to do when a video cannot be read by cv2.VideoCapture
[Beanstalk] What to do when an error occurs with import uuid
What to do when the jupyterlab extension settings are not reflected
What to do if Insecure Platform Warning appears when running Python
What to do if you get a must override `get_config` error when trying to model.save in Keras
What to do if PyAudio cannot be installed on Python 3.7, 3.8, 3.9 on Windows
[PySerial] What to think when a "could not open port'/ dev / cu." Error appears during serial communication on the micro: bit
What to do when the value type is ambiguous in Python?
What to do if grep: empty (sub) expression appears on Mac grep
What to do if you get a Permission denied (public key) error when trying to pull on Github
[Memorandum] What to do when a warning appears after executing pip list
What to do if pyenv install does not proceed with an error
[Python] What to do when an error related to SSL authentication is returned
What to do if an error occurs when importing numpy with VScode
What to do if you get an error when trying to load mnist
What to do when the warning "The environment is in consistent ..." appears in the Anaconda environment
What to do if you get an error when installing Dlib (Ubuntu)
[OSX] [pyenv] What to do when an SSL error occurs in pip
What to do when psycopg2 throws an error when pipenv lock under Pipenv environment
Notes on what to do if "macOS 11 or later required!" Appears in Big Sur or pyarrow2.0.0 cannot be installed
Example of what to do when the sample script does not work (OpenCV-Python)
What to do if CERTIFICATE_VERIFY_FAILED occurs when nltk.download () is done on macOS pyhon
[python] What to do when an error occurs in send_keys of headless chrome
What to do when SSL error occurs in pip in Windows10, miniconda, VScode environment
[Ubuntu 18.04 LTS] What to do when the screen resolution cannot be selected [NVIDIA]
What to do if you get an error when installing python with pyenv
What to do when [Errno 2] No such file or directory appears in Python
What to do when the graph does not appear in jupyter (ipython) notebook
What to do if NotADirectoryError: [Errno 20] Not a directory:'xdg-settings' appears in jupyter notebook
[EC2] What to do when selenium is stuck and processing does not proceed
What to do if Japanese language support is not completely installed on Ubuntu 16.04
What to do if an SSL connection error (ssl.SSLError: [SSL: DH_KEY_TOO_SMALL]) occurs on Ubuntu 20.04
What to do if pip cannot be installed
What to do when PermissionError of tempfile.mkstemp occurs
To write to Error Repoting in Python on GAE
What to do if "export" keeps appearing on terminal when trying to put Python on macOS
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if you get an error when importing matplotlib in Python (Mac)
What to do if Python IntelliSense is not displayed in VS Code on Windows