Using PostgreSQL with App Engine Standard - postgresql

I trying to use postgres on app engine standard with python2.7 environment.
I use sqlalchemy + pg8000 for connection, connection string looks like:
postgresql+pg8000://user:password#/dbname?unix_sock=/cloudsql/project:us-central1:db
It works on local machine, but when I deploy it, I receive an error:
AttributeError: 'Connection' object has no attribute '_usock'
How to configure the connection to the database?
Full traceback:
Traceback (most recent call last):
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/e416f9a06334486a/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/e416f9a06334486a/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/e416f9a06334486a/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/main.py", line 15, in <module>
db.engine.execute('select ')
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/engine/base.py", line 2074, in execute
connection = self.contextual_connect(close_with_result=True)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/engine/base.py", line 2123, in contextual_connect
self._wrap_pool_connect(self.pool.connect, None),
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/engine/base.py", line 2158, in _wrap_pool_connect
return fn()
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 400, in connect
return _ConnectionFairy._checkout(self)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 788, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 529, in checkout
rec = pool._do_get()
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 1193, in _do_get
self._dec_overflow()
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/util/langhelpers.py", line 66, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 1190, in _do_get
return self._create_connection()
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 347, in _create_connection
return _ConnectionRecord(self)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 474, in __init__
self.__connect(first_connect_check=True)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 671, in __connect
connection = pool._invoke_creator(self)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/engine/strategies.py", line 106, in connect
return dialect.connect(*cargs, **cparams)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/engine/default.py", line 412, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/pg8000/__init__.py", line 112, in connect
application_name, max_prepared_statements)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/pg8000/core.py", line 1183, in __init__
self._usock.close()
AttributeError: 'Connection' object has no attribute '_usock'

Related

Error when using find/find_one pymongo methods when on an apache2 server (mongodb atlas)

when using find/find_one pymongo methods when on an apache2 server i get the following error :
No <class 'cryptography.x509.extensions.TLSFeature'> extension was found
when using pymongo on an apache2 server to connect and insert or delete in my mongodb collections it works just fine, but when i try to pull something out of the database (using find or find_one methods) i get an error, please note that this error only occurs while running the apache2 server, because when i connected and used find methods in a locally run python script it gave me the information without any errors.
if it is of any relevance, the web framework i am using is flask.
Edit : As for what is producing the error i dont know for sure, so here are the logs.
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2525, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1822, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1820, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1796, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/var/www/html/srv21/SRVApp.py", line 17, in downloadpage
ThreadID = ThreadID.next()
File "/usr/local/lib/python3.10/dist-packages/pymongo/cursor.py", line 1248, in next
if len(self.__data) or self._refresh():
File "/usr/local/lib/python3.10/dist-packages/pymongo/cursor.py", line 1165, in _refresh
self.__send_message(q)
File "/usr/local/lib/python3.10/dist-packages/pymongo/cursor.py", line 1052, in __send_message
response = client._run_operation(
File "/usr/local/lib/python3.10/dist-packages/pymongo/_csot.py", line 105, in csot_wrapper
return func(self, *args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/pymongo/mongo_client.py", line 1330, in _run_operation
return self._retryable_read(
File "/usr/local/lib/python3.10/dist-packages/pymongo/_csot.py", line 105, in csot_wrapper
return func(self, *args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/pymongo/mongo_client.py", line 1442, in _retryable_read
with self._socket_from_server(read_pref, server, session) as (sock_info, read_pref):
File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.10/dist-packages/pymongo/mongo_client.py", line 1282, in _socket_from_server
with self._get_socket(server, session) as sock_info:
File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.10/dist-packages/pymongo/mongo_client.py", line 1217, in _get_socket
with server.get_socket(handler=err_handler) as sock_info:
File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.10/dist-packages/pymongo/pool.py", line 1407, in get_socket
sock_info = self._get_socket(handler=handler)
File "/usr/local/lib/python3.10/dist-packages/pymongo/pool.py", line 1520, in _get_socket
sock_info = self.connect(handler=handler)
File "/usr/local/lib/python3.10/dist-packages/pymongo/pool.py", line 1358, in connect
sock = _configured_socket(self.address, self.opts)
File "/usr/local/lib/python3.10/dist-packages/pymongo/pool.py", line 1061, in _configured_socket
sock = ssl_context.wrap_socket(sock, server_hostname=host)
File "/usr/local/lib/python3.10/dist-packages/pymongo/pyopenssl_context.py", line 369, in wrap_socket
ssl_conn.do_handshake()
File "/usr/local/lib/python3.10/dist-packages/pymongo/pyopenssl_context.py", line 125, in do_handshake
return self._call(super(_sslConn, self).do_handshake, *args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/pymongo/pyopenssl_context.py", line 108, in _call
return call(*args, **kwargs)
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1894, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1603, in _raise_ssl_error
self._context._ocsp_helper.raise_if_problem()
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 319, in raise_if_problem
raise self._problems.pop(0)
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 539, in wrapper
valid = callback(conn, ocsp_data, data)
File "/usr/local/lib/python3.10/dist-packages/pymongo/ocsp_support.py", line 298, in _ocsp_callback
ext = _get_extension(cert, _TLSFeature)
File "/usr/local/lib/python3.10/dist-packages/pymongo/ocsp_support.py", line 114, in _get_extension
return cert.extensions.get_extension_for_class(klass)
File "/usr/local/lib/python3.10/dist-packages/cryptography/x509/extensions.py", line 135, in get_extension_for_class
raise ExtensionNotFound(
cryptography.x509.extensions.ExtensionNotFound: No <class 'cryptography.x509.extensions.TLSFeature'> extension was found

Why Pgadmin gives me 500 error? _pickle.PicklingError: Can't pickle <class 'wtforms.form.Meta'>: attribute lookup Meta on wtforms.form failed

Occasionally, Pgadmin gives me the 500 error in a browser. After reloading the page, the issue disappears for a while and then comes back again. Here's the log I see while getting the error:
[2022-01-21 14:35:21 +0000] [93] [ERROR] Error handling request /authenticate/login
Traceback (most recent call last):
File "/venv/lib/python3.8/site-packages/gunicorn/workers/gthread.py", line 271, in handle
keepalive = self.handle_request(req, conn)
File "/venv/lib/python3.8/site-packages/gunicorn/workers/gthread.py", line 323, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/venv/lib/python3.8/site-packages/flask/app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "/pgadmin4/pgAdmin4.py", line 77, in __call__
return self.app(environ, start_response)
File "/venv/lib/python3.8/site-packages/werkzeug/middleware/proxy_fix.py", line 169, in __call__
return self.app(environ, start_response)
File "/venv/lib/python3.8/site-packages/flask_socketio/__init__.py", line 43, in __call__
return super(_SocketIOMiddleware, self).__call__(environ,
File "/venv/lib/python3.8/site-packages/engineio/middleware.py", line 74, in __call__
return self.wsgi_app(environ, start_response)
File "/venv/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "/venv/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "/venv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/venv/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/venv/lib/python3.8/site-packages/flask/app.py", line 1953, in full_dispatch_request
return self.finalize_request(rv)
File "/venv/lib/python3.8/site-packages/flask/app.py", line 1970, in finalize_request
response = self.process_response(response)
File "/venv/lib/python3.8/site-packages/flask/app.py", line 2269, in process_response
self.session_interface.save_session(self, ctx.session, response)
File "/pgadmin4/pgadmin/utils/session.py", line 307, in save_session
self.manager.put(session)
File "/pgadmin4/pgadmin/utils/session.py", line 166, in put
self.parent.put(session)
File "/pgadmin4/pgadmin/utils/session.py", line 270, in put
dump(
_pickle.PicklingError: Can't pickle <class 'wtforms.form.Meta'>: attribute lookup Meta on wtforms.form failed
The issue appeared after enabling Oauth2 authentication. I've tried using different version but no luck.
Pgadmin is running in Kubernetes.
Please try setting
PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION = False in configuration file according to your operating system as mentioned here.

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) fe_sendauth: no password supplied

i am trying to run this simple flask app and I keep getting this error in the terminal when trying to run the flask app
FLASK_APP=app.py flask run
i keep getting this error :
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) fe_sendauth: no password supplied
here is my app:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres#localhost:5432/testdb'
db = SQLAlchemy(app)
class Person(db.Model):
__tablename__ = 'persons'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(), nullable=False)
db.create_all()
#app.route('/')
def index():
return 'Hello World!'
just to clarify i have psycopg2, flask-SQLAlchemy and all dependencies installed AND THERE IS NO PASSWORD FOR USER postgres by default and i haven't changed that and i can log in to database as postgres using psql without password without any problems.
Full error output:
FLASK_APP=app.py flask run
* Serving Flask app "app.py"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
/usr/lib/python3/dist-packages/flask_sqlalchemy/__init__.py:800: UserWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True to suppress this warning.
warnings.warn('SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True to suppress this warning.')
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 1122, in _do_get
return self._pool.get(wait, self._timeout)
File "/usr/lib/python3/dist-packages/sqlalchemy/util/queue.py", line 145, in get
raise Empty
sqlalchemy.util.queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 2147, in _wrap_pool_connect
return fn()
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 387, in connect
return _ConnectionFairy._checkout(self)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 766, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 516, in checkout
rec = pool._do_get()
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 1138, in _do_get
self._dec_overflow()
File "/usr/lib/python3/dist-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/usr/lib/python3/dist-packages/sqlalchemy/util/compat.py", line 187, in reraise
raise value
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 1135, in _do_get
return self._create_connection()
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 333, in _create_connection
return _ConnectionRecord(self)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 461, in __init__
self.__connect(first_connect_check=True)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 651, in __connect
connection = pool._invoke_creator(self)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/strategies.py", line 105, in connect
return dialect.connect(*cargs, **cparams)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/default.py", line 393, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/home/aa/.local/lib/python3.6/site-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: fe_sendauth: no password supplied
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/aa/.local/bin/flask", line 11, in <module>
sys.exit(main())
File "/home/aa/.local/lib/python3.6/site-packages/flask/cli.py", line 967, in main
cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
File "/home/aa/.local/lib/python3.6/site-packages/flask/cli.py", line 586, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "/home/aa/.local/lib/python3.6/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/aa/.local/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/aa/.local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/aa/.local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/aa/.local/lib/python3.6/site-packages/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/home/aa/.local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/aa/.local/lib/python3.6/site-packages/flask/cli.py", line 848, in run_command
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
File "/home/aa/.local/lib/python3.6/site-packages/flask/cli.py", line 305, in __init__
self._load_unlocked()
File "/home/aa/.local/lib/python3.6/site-packages/flask/cli.py", line 330, in _load_unlocked
self._app = rv = self.loader()
File "/home/aa/.local/lib/python3.6/site-packages/flask/cli.py", line 388, in load_app
app = locate_app(self, import_name, name)
File "/home/aa/.local/lib/python3.6/site-packages/flask/cli.py", line 240, in locate_app
__import__(module_name)
File "/home/aa/Desktop/Udacity - FullStackND 2020/FullStackND2020/Practice Projects/flask hello world app/app.py", line 18, in <module>
db.create_all()
File "/usr/lib/python3/dist-packages/flask_sqlalchemy/__init__.py", line 972, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/usr/lib/python3/dist-packages/flask_sqlalchemy/__init__.py", line 964, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File "/usr/lib/python3/dist-packages/sqlalchemy/sql/schema.py", line 3934, in create_all
tables=tables)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1928, in _run_visitor
with self._optional_conn_ctx_manager(connection) as conn:
File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1921, in _optional_conn_ctx_manager
with self.contextual_connect() as conn:
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 2112, in contextual_connect
self._wrap_pool_connect(self.pool.connect, None),
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 2151, in _wrap_pool_connect
e, dialect, self)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1465, in _handle_dbapi_exception_noconnection
exc_info
File "/usr/lib/python3/dist-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/usr/lib/python3/dist-packages/sqlalchemy/util/compat.py", line 186, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 2147, in _wrap_pool_connect
return fn()
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 387, in connect
return _ConnectionFairy._checkout(self)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 766, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 516, in checkout
rec = pool._do_get()
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 1138, in _do_get
self._dec_overflow()
File "/usr/lib/python3/dist-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/usr/lib/python3/dist-packages/sqlalchemy/util/compat.py", line 187, in reraise
raise value
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 1135, in _do_get
return self._create_connection()
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 333, in _create_connection
return _ConnectionRecord(self)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 461, in __init__
self.__connect(first_connect_check=True)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 651, in __connect
connection = pool._invoke_creator(self)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/strategies.py", line 105, in connect
return dialect.connect(*cargs, **cparams)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/default.py", line 393, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/home/aa/.local/lib/python3.6/site-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) fe_sendauth: no password supplied
Other than just setting a password, you can log in without a password by:
Enable trust authentication, eg echo "local all all trust" | sudo tee -a /etc/postgresql/10/main/pg_hba.conf
Create a role with login access with the same username as your local username, eg if whoami returns myname, then sudo -u postgres psql -c "CREATE ROLE myname WITH LOGIN"
Use sqlalchemy's postgresql unix domain connection instead of tcp (ref), eg "postgres+psycopg2://myname#/mydb"
Note that this requires installing pip3 install psycopg2-binary
so apparently you need a password to connect to database from SQLAlchemy, I was able to work around this by simply creating a password or adding new user with password.
let me know if there is a different work around/solution

scrapy sending mail got an ERROR: Unable to send mail. object of type 'module' has no len()

I wanna send email when spider closed, code is like this:
def close(spider, reason):
# mailer = MailSender.from_settings(self.settings)
from scrapy.mail import MailSender
mailer = MailSender(
smtphost="smtp.163.com",
mailfrom="rhys***#163.com",
smtpuser="rhys***g#163.com",
smtppass="***",
smtpport=25
)
body = u"""
content
"""
subject = u'title'
mailer.send(to=["rhys***#qq.com"],
subject=subject.encode("utf-8"),
body=body.encode("utf-8"),
cc=['12202012**#qq.com'])
But I got an error like this:
[twisted] CRITICAL: Unhandled Error
Traceback (most recent call last):
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/python/log.py", line 103, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/python/log.py", line 86, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/python/context.py", line 122, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/python/context.py", line 85, in callWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/internet/posixbase.py", line 597, in _doReadOrWrite
why = selectable.doRead()
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/internet/tcp.py", line 208, in doRead
return self._dataReceived(data)
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/internet/tcp.py", line 214, in _dataReceived
packages/twisted/internet/tcp.py", line 214, in _dataReceived
rval = self.protocol.dataReceived(data)
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/protocols/tls.py", line 330, in dataReceived
self._flushReceiveBIO()
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/protocols/tls.py", line 295, in _flushReceiveBIO
ProtocolWrapper.dataReceived(self, bytes)
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/protocols/policies.py", line 120, in dataReceived
self.wrappedProtocol.dataReceived(data)
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/protocols/basic.py", line 571, in dataReceived
why = self.lineReceived(line)
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/mail/smtp.py", line 995, in lineReceived
why = self._okresponse(self.code, b'\n'.join(self.resp))
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/mail/smtp.py", line 1044, in smtpState_to
return self.smtpState_toOrData(0, b'')
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/mail/smtp.py", line 1062, in smtpState_toOrData
self.sendLine(b'RCPT TO:' + quoteaddr(self.lastAddress))
File "/home/rhys/.pyenv/versions/2.7.5/envs/p2spider/lib/python2.7/site-
packages/twisted/mail/smtp.py", line 179, in quoteaddr
res = email.utils.parseaddr(addr)
File "/home/rhys/.pyenv/versions/2.7.5/lib/python2.7/email/utils.py", li
ne 215, in parseaddr
addrs = _AddressList(addr).addresslist
File "/home/rhys/.pyenv/versions/2.7.5/lib/python2.7/email/_parseaddr.py
", line 457, in __init__
self.addresslist = self.getaddrlist()
File "/home/rhys/.pyenv/versions/2.7.5/lib/python2.7/email/_parseaddr.py
", line 217, in getaddrlist
while self.pos < len(self.field):
exceptions.TypeError: object of type 'module' has no len()
anybody can explain why?
I use python2.7 and scapy1.4. if I comment the code mentioned above everything is just ok
thanks
I bumped to twisted 17.9 and the problem went away.

forbidden error using pytube on pythonanywhere

I have a similar issue to that which is highlited at https://www.pythonanywhere.com/forums/topic/2688/
the only difference is that I am using flask, and the module I am using is pytube. I trust that you shall help, the error message displayed is:
Traceback (most recent call last):
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functionsrule.endpoint
File "/home/*username*/<project>/app.py", line 49, in upload
ytube = YouTube(url)
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/pytube/api.py", line 66, in init
self.from_url(url)
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/pytube/api.py", line 158, in from_url
video_data = self.get_video_data()
File "/home/*username*/.virtualenvs/*project*/local/lib/python2.7/site-packages/pytube/api.py", line 254, in get_video_data
response = urlopen(self.url)
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 404, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 422, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1222, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
raise URLError(err) URLError: <urlopen error Tunnel connection failed: 403 Forbidden>
Youtube doesn't allow downloading videos through their API, so all of the scripts that download youtube videos scrape the www site, and we don't allow scraping from free accounts.
more info here: http://help.pythonanywhere.com/pages/403ForbiddenError