ValueError: I/O operation on closed file while visualizing my protein - python

from Bio.PDB import *
import nglview as nv
import ipywidgets
pdb_parser = PDBParser()
structure = pdb_parser.get_structure("PHA-L", "C:\\Users\\asus\\Downloads\\1FAT.pdb")
view = nv.show_biopython(structure)
I was Expecting a plot of the protein structure
Below are the tracebacks
Traceback (most recent call last):
File "C:\Python311\Lib\site-packages\flask\app.py", line 2525, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\flask\app.py", line 1822, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\flask\app.py", line 1820, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\flask\app.py", line 1796, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\asus\Desktop\Rscripts\app.py", line 15, in view
pdbview(path_file)
File "C:\Users\asus\Desktop\Rscripts\mol.py", line 12, in pdbview
r.source(path+"NGLviewer.R")
^^^^^^^^
File "C:\Python311\Lib\site-packages\rpy2\robjects\__init__.py", line 434, in __getattribute__
return self.__getitem__(attr)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\rpy2\robjects\__init__.py", line 440, in __getitem__
res = conversion.get_conversion().rpy2py(res)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\functools.py", line 909, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\rpy2\robjects\conversion.py", line 252, in _rpy2py
raise NotImplementedError(
NotImplementedError: Conversion 'rpy2py' not defined for objects of type '<class 'rpy2.rinterface.SexpClosure'>'
127.0.0.1 - - [28/Nov/2022 13:39:11] "GET / HTTP/1.1" 500 -

Related

ValueError: Circular reference detected

I had a code of around 287 lines, when it is executed on command prompt everything works fine, but when it is compiled on localhost with Flask it is showing following error:
ERROR:series-api:Exception on /papis/get-series [GET]
Traceback (most recent call last):
File "C:\Users\mkiak\AppData\Roaming\Python\Python39\site-packages\flask\app.py", line 2070, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\mkiak\AppData\Roaming\Python\Python39\site-packages\flask\app.py", line 1515, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\mkiak\AppData\Roaming\Python\Python39\site-packages\flask\app.py", line 1513, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\mkiak\AppData\Roaming\Python\Python39\site-packages\flask\app.py", line 1499, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "E:\series-api.py", line 275, in getSeries
return jsonify(result)
File "C:\Users\mkiak\AppData\Roaming\Python\Python39\site-packages\flask\json\__init__.py", line 348, in jsonify
f"{dumps(data, indent=indent, separators=separators)}\n",
File "C:\Users\mkiak\AppData\Roaming\Python\Python39\site-packages\flask\json\__init__.py", line 129, in dumps
rv = _json.dumps(obj, **kwargs)
File "C:\Program Files\Python39\lib\json\__init__.py", line 234, in dumps
return cls(
File "C:\Program Files\Python39\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Program Files\Python39\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
ValueError: Circular reference detected
You have a reference to object inside the object itself. Minimal example:
import json
d = {}
d["a"] = d
json.dumps(d) # raises ValueError: Circular reference detected
You can try to create a (deep) copy of the object.
d = {}
d["a"] = d.copy()
json.dumps(d)

RQ-dashboard reports empty time data

I'm trying to build a job queue with Redis Queue and RQ-scheduler. But from RQ-dashboard I get the following error when I try to load the jobs tab. I see that the jobs are added because the job count is going up.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/rq_dashboard/web.py", line 101, in _wrapped
result_dict = f(*args, **kwargs)
File "/rq_dashboard/web.py", line 428, in list_jobs
queue_name, registry_name, offset, per_page
File "/rq_dashboard/web.py", line 233, in get_queue_registry_jobs_count
current_queue_jobs = [queue.fetch_job(job_id) for job_id in job_ids]
File "/rq_dashboard/web.py", line 233, in <listcomp>
current_queue_jobs = [queue.fetch_job(job_id) for job_id in job_ids]
File "/usr/local/lib/python3.7/site-packages/rq/queue.py", line 147, in fetch_job
job = self.job_class.fetch(job_id, connection=self.connection)
File "/usr/local/lib/python3.7/site-packages/rq/job.py", line 299, in fetch
job.refresh()
File "/usr/local/lib/python3.7/site-packages/rq/job.py", line 506, in refresh
self.restore(data)
File "/usr/local/lib/python3.7/site-packages/rq/job.py", line 474, in restore
self.started_at = str_to_date(obj.get('started_at'))
File "/usr/local/lib/python3.7/site-packages/rq/utils.py", line 256, in str_to_date
return utcparse(as_text(date_str))
File "/usr/local/lib/python3.7/site-packages/rq/utils.py", line 172, in utcparse
return datetime.datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ')
File "/usr/local/lib/python3.7/_strptime.py", line 577, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/local/lib/python3.7/_strptime.py", line 359, in _strptime
(data_string, format))
ValueError: time data '' does not match format '%Y-%m-%dT%H:%M:%SZ'
23:48:49: Exception on /0/data/jobs/default/queued/8/1.json [GET]
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/rq/utils.py", line 169, in utcparse
return datetime.datetime.strptime(string, _TIMESTAMP_FORMAT)
File "/usr/local/lib/python3.7/_strptime.py", line 577, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/local/lib/python3.7/_strptime.py", line 359, in _strptime
(data_string, format))
ValueError: time data '' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
I add the jobs as follows:
from redis import Redis
from rq import Queue
from rq_scheduler import Scheduler
from datetime import datetime
import functions
tables = [["materialen", 2260, "artikelcode"], ["contracten", 4200, "contractnummer"], ["klantgegevens", 101, "klantnummer"], ["servicebonnen", 3600, "servicebonnummer"], [
"contactpersonen", 105, "klantnummer"], ["archief", 3900, "servicebonnummer"], ["documenten", 4240, "volgnummer"], ["memos", 3609, "servicebonnummer"]]
# Get a scheduler for the "default" queue
scheduler = Scheduler(connection=Redis('127.0.0.1'))
for tableInfo in tables:
scheduler.schedule(
scheduled_time=datetime.utcnow(),
timeout=120,
description=tableInfo[0],
func=functions.updateTable,
args=[tableInfo],
interval=60,
repeat=None,
)
I can't figure out what I'm doing wrong? What variable is empty or do I set the scheduled time incorrectly?
The issue is because rq-dashboard relies on rq v1.3.0 and it looks like it has some API differences from rq v1.4.0+.
So, ideally this should be fixed by rq-dashboard maintainers. Here is an opened issue and a pending PR that's mentioned there: https://github.com/Parallels/rq-dashboard/issues/362

Google App Engine/NDB: "BadValueError: Expected Key, got None" for saving perfectly fine entity

I'm currently porting a web app to Google App Engine, Python 3, Standard Environment. (So I'm new to GAE and NDB).
I have a bug here that I don't understand. I obtain an entity like so, the adjust properties, then save.
sourceUsers = User.query().filter(User.email == request.form.get('sourceUserEmail')).fetch(1)
if sourceUsers:
sourceUser = sourceUsers[0]
# manipulation:
sourceUser.sentInvitationSubscriptionKeys.append(subscription.key)
# verify key:
assert sourceUser.key != None
sourceUser.put()
But the saving triggers the following traceback:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/yanone/Code/Google App Engine/typeworldappengine/main.py", line 500, in api
sourceUser.put()
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/_options.py", line 89, in wrapper
return wrapped(*pass_args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/utils.py", line 78, in wrapper
return wrapped(*args, **new_kwargs)
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/utils.py", line 109, in positional_wrapper
return wrapped(*args, **kwds)
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/model.py", line 4914, in _put
return self._put_async(_options=kwargs["_options"]).result()
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/tasklets.py", line 190, in result
self.check_success()
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/tasklets.py", line 137, in check_success
raise self._exception
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/tasklets.py", line 312, in _advance_tasklet
yielded = self.generator.send(send_value)
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/model.py", line 4974, in put
ds_entity = _entity_to_ds_entity(self)
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/model.py", line 722, in _entity_to_ds_entity
names = prop._to_datastore(entity, data)
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/model.py", line 2063, in _to_datastore
value = self._get_base_value_unwrapped_as_list(entity)
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/model.py", line 1551, in _get_base_value_unwrapped_as_list
wrapped = self._get_base_value(entity)
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/model.py", line 1537, in _get_base_value
return self._apply_to_values(entity, self._opt_call_to_base_type)
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/model.py", line 1834, in _apply_to_values
value[:] = map(function, value)
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/model.py", line 1612, in _opt_call_to_base_type
value = _BaseValue(self._call_to_base_type(value))
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/model.py", line 1671, in _call_to_base_type
return call(value)
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/model.py", line 1801, in call
new_value = method(self, value)
File "/usr/local/lib/python3.7/site-packages/google/cloud/ndb/model.py", line 3344, in _validate
"Expected Key, got {!r}".format(value)
google.cloud.ndb.exceptions.BadValueError: Expected Key, got None
In the debugging, I even made sure that the entity has a key (assert sourceUser.key != None). So I really don't get it. What am I doing wrong?
Mind you, all other entities save fine. Just this one doesn't.
Thank you.
I dont think this entity's primary key is the problem. It's probably another Key field on the object.
Whats the schema for the rest of you User object?

Problem in response with alexa custom skill using ngrok

I'm working on Alexa custom skill by using Alexa voice control to control raspberry gpio pins, I followed each and every steps mentioned here https://www.instructables.com/id/Control-Raspberry-Pi-GPIO-With-Amazon-Echo-and-Pyt/ but this is giving me response error
I tried degrading cryptography to 2.2.
Re-starting the server.
Re-building the model.
logging.getLogger("flask_ask").setLevel(logging.DEBUG)
#ask.intent('GPIOControlIntent', mapping={'status': 'status', 'pin': 'pin'})
def gpio_control(status, pin):
try:
pinNum = int(pin)
except Exception as e:
return statement('Pin number not valid.')
GPIO.setup(pinNum, GPIO.OUT)
if status in ['on', 'high']: GPIO.output(pinNum, GPIO.HIGH)
if status in ['off', 'low']: GPIO.output(pinNum, GPIO.LOW)
return statement('Turning pin {} {}'.format(pin, status))
The error I got:
127.0.0.1 - - [13/Jul/2019 00:04:25] "POST / HTTP/1.1" 500 - Traceback (most recent call last): File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response) File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e) File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb) File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request() File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e) File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb) File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request() File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args) File "/home/pi/.local/lib/python2.7/site-packages/flask_ask/core.py", line 728, in _flask_view_func
ask_payload = self._alexa_request(verify=self.ask_verify_requests) File "/home/pi/.local/lib/python2.7/site-packages/flask_ask/core.py", line 662, in _alexa_request
cert = verifier.load_certificate(cert_url) File "/home/pi/.local/lib/python2.7/site-packages/flask_ask/verifier.py", line 21, in load_certificate
if not _valid_certificate(cert): File "/home/pi/.local/lib/python2.7/site-packages/flask_ask/verifier.py", line 63, in _valid_certificate
value = str(extension) File "/home/pi/.local/lib/python2.7/site-packages/OpenSSL/crypto.py", line 779, in __str__
return self._subjectAltNameString() File "/home/pi/.local/lib/python2.7/site-packages/OpenSSL/crypto.py", line 740, in _subjectAltNameString
method = _lib.X509V3_EXT_get(self._extension) AttributeError: 'module' object has no attribute 'X509V3_EXT_get'
127.0.0.1 - - [13/Jul/2019 00:04:28] "POST / HTTP/1.1" 500 - Traceback (most recent call last): File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response) File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e) File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb) File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request() File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e) File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb) File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request() File "/home/pi/.local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args) File "/home/pi/.local/lib/python2.7/site-packages/flask_ask/core.py", line 728, in _flask_view_func
ask_payload = self._alexa_request(verify=self.ask_verify_requests) File "/home/pi/.local/lib/python2.7/site-packages/flask_ask/core.py", line 662, in _alexa_request
cert = verifier.load_certificate(cert_url) File "/home/pi/.local/lib/python2.7/site-packages/flask_ask/verifier.py", line 21, in load_certificate
if not _valid_certificate(cert): File "/home/pi/.local/lib/python2.7/site-packages/flask_ask/verifier.py", line 63, in _valid_certificate
value = str(extension) File "/home/pi/.local/lib/python2.7/site-packages/OpenSSL/crypto.py", line 779, in __str__
return self._subjectAltNameString() File "/home/pi/.local/lib/python2.7/site-packages/OpenSSL/crypto.py", line 740, in _subjectAltNameString
method = _lib.X509V3_EXT_get(self._extension) AttributeError: 'module' object has no attribute 'X509V3_EXT_get'
Try degrading it to less than 2.2
pip install 'cryptography<2.2'

Using for loops in sqlalchemy query

So i wanna use a for loop in a query and pull results if a record's field is equal to an object's property (in a list of objects) how do i do that? This is my code:
you = session.query(Users).filter_by(id=login_session['userid']).first()
friends = session.query(Friends).filter_by(user_id=login_session['userid']).all()
dashboard = session.query(Markers).filter(Markers.owner == f.friend_id for f in friends).all()
but then i get this:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/pearadox6/travellr/app.py", line 423, in feed
dashboard = session.query(Markers).filter(Markers.owner == f.friend_id for f in friends).all()
File "<string>", line 1, in <lambda>
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 51, in generate
fn(self, *args[1:], **kw)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 1216, in filter
criterion = expression._literal_as_text(criterion)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/expression.py", line 1521, in _literal_as_text
"SQL expression object or string expected."
ArgumentError: SQL expression object or string expected.
Why?
Why?
Because you can't pass a generator object as an argument for filter:
session.query(Markers).filter(Markers.owner == f.friend_id for f in friends).all()
Use in_ with a list instead:
session.query(Markers).filter(Markers.owner.in_([f.friend_id for f in friends)]).all()

Categories

Resources