Hey I've been trying to encrypt some inputted data into a SQLalchemy database. However I keep receiving this error when trying to retrieve the decyrpted data from the database. Any help would be much appreciated.
key = Fernet.generate_key()
fernet = Fernet(key)
Encryption part:
fnam = str(form.first_name.data.lower())
Cfname = bytes(fnam, 'utf-8')
Efname = str(fernet.encrypt(Cfname))
lnam = str(form.last_name.data.lower())
Clname = bytes(lnam,'utf-8')
Elname = str(fernet.encrypt(Clname))
print(Efname)
print(Elname)
appoint.first_name =Efname
appoint.last_name = Elname
Decryption part:
info = user.query.filter_by(id=user.id).first()
finam = info.first_name
lanam = info.last_name
first = str(fernet.decrypt(bytes(finam,'utf-8')))
last = str(fernet.decrypt(bytes(lanam,'utf-8')))
Error message
Traceback (most recent call last):
File "appsec2\venv\lib\site-packages\flask\app.py", line 2095, in __call__
return self.wsgi_app(environ, start_response)
File "appsec2\venv\lib\site-packages\flask\app.py", line 2080, in wsgi_app
response = self.handle_exception(e)
File "appsec2\venv\lib\site-packages\flask\app.py", line 2077, in wsgi_app
response = self.full_dispatch_request()
File "appsec2\venv\lib\site-packages\flask\app.py", line 1525, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\txzsp\OneDrive\Documents\Poly sch stuff\Y2, S1\appsec2\venv\lib\site-packages\flask\app.py", line 1523, in full_dispatch_request
rv = self.dispatch_request()
File "appsec2\venv\lib\site-packages\flask\app.py", line 1509, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "appsec2\appsec\routes.py", line 908, in retrieveConsultation
first = str(fernet.decrypt(bytes(finam,'utf-8')))
File appsec2\venv\lib\site-packages\cryptography\fernet.py", line 83, in decrypt
timestamp, data = Fernet._get_unverified_token_data(token)
File "appsec2\venv\lib\site-packages\cryptography\fernet.py", line 115, in _get_unverified_token_data
raise InvalidToken
cryptography.fernet.InvalidToken
Related
My function below is supposed to trigger the sending of a pub/sub message. However, I get a key error. I am not sure why it is throwing this error.
def run(event, context):
pubsub_message = base64.b64decode(event['data']).decode('utf-8')
week = datetime.date.today().isocalendar()[1]
year = datetime.date.today().year
file_name = f"Times week {year}.{week}.xlsx"
file_path = f"/tmp/{file_name}"
data = DataIngestion().get_data(pubsub_message)
data = pd.DataFrame.from_records(data)
data.drop(columns='_type', inplace=True)
for col in data.columns:
if "Open" in col or "Close" in col:
data[col] = pd.to_datetime(data[col], format= '%H:%M', errors="coerce").dt.time
data[col] = data[col].replace(np.nan, 'closed', regex=True)
check_unique(data)
data.to_excel(file_path, index=False, encoding='utf-8')
filetoSend(file_path, file_name, week)
Here is the error:
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/__init__.py", line 171, in view_func
function(data, context)
File "/workspace/main.py", line 92, in run
pubsub_message = base64.b64decode(event['data']).decode('utf-8')
KeyError: 'data'
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)
Hi I am scraping data from a website and converting text to mp3 but every time it give me this error :
Traceback (most recent call last):
File "/home/awais/.local/lib/python2.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/awais/.local/lib/python2.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/awais/.local/lib/python2.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/awais/.local/lib/python2.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/awais/.local/lib/python2.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/awais/Desktop/sipgateio-incomingcall-python-master/incoming_call/__main__.py", line 93, in handle_on_dtmf
ttmp3.save("bbc.mp3")
File "/home/awais/.local/lib/python2.7/site-packages/gtts/tts.py", line 295, in save
self.write_to_fp(f)
File "/home/awais/.local/lib/python2.7/site-packages/gtts/tts.py", line 272, in write_to_fp
raise gTTSError(tts=self)
gTTSError: Failed to connect. Probable cause: Host 'https://translate.google.en/' is not reachable
This is what my code look like :
URL = requests.get("https://www.bbc.co.uk/news")
soup = BeautifulSoup(URL.text, 'html.parser')
headlines = soup.select(".gs-c-promo-heading__title")
all = ""
for h in headlines:
h=h.text
h = h.encode('ascii', 'ignore').decode('ascii')
all = str(all) + " " + str(h)
print(all)
ttmp3 = gTTS(all, "en")
ttmp3.save("bbc.mp3")
I am stuck here for last 1 day , please help me
Thank you very much guys , I resolved it by changing this parameter :
ttmp3 = gTTS(text=all,lang="en",tld="com")
By putting tld="com" we can fix it
I want to try to make a dataframe from pdfreader, with the column name is isi1. but why do I get an error ValueError: DataFrame constructor not properly called !. what should i do to fix this error. help from anyone when needed for this problem.
this is my code
if request.method == 'POST':
f = request.files['file']
f.save(f.filename)
pdfreader = PyPDF2.PdfFileReader(open('C:/Users/Novilia/PycharmProjects/tesaja/' + f.filename, 'rb'))
from pandas import DataFrame
df1 = DataFrame(pdfreader, columns=['isi1'])
#vect = count_vect.transform(['isi1']).toarray()
df1['label1'] = text_clf.predict(df1['isi1'])
df1.append(['label1'])
hasil = (df1.isi1[df1['label1'] == 'positif'])
len(hasil)
hasil_list = hasil.values.tolist()
stringList = ' '.join([str(item) for item in hasil_list])
hasil_ringkas = stringList
return render_template('result.html', ringkasan = hasil_ringkas)
the error is
ValueError
ValueError: DataFrame constructor not properly called!
Traceback (most recent call last)
File "C:\Users\Novilia\PycharmProjects\tesaja\venv\lib\site-packages\flask\app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\Novilia\PycharmProjects\tesaja\venv\lib\site-packages\flask\app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\Novilia\PycharmProjects\tesaja\venv\lib\site-packages\flask\app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Novilia\PycharmProjects\tesaja\venv\lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\Novilia\PycharmProjects\tesaja\venv\lib\site-packages\flask\app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\Novilia\PycharmProjects\tesaja\venv\lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\Novilia\PycharmProjects\tesaja\venv\lib\site-packages\flask\app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Novilia\PycharmProjects\tesaja\venv\lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\Novilia\PycharmProjects\tesaja\venv\lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\Novilia\PycharmProjects\tesaja\venv\lib\site-packages\flask\app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\Novilia\PycharmProjects\tesaja\app.py", line 79, in summarize
df1 = DataFrame(pdfreader, columns=['isi1'])
File "C:\Users\Novilia\PycharmProjects\tesaja\venv\lib\site-packages\pandas\core\frame.py", line 509, in __init__
raise ValueError("DataFrame constructor not properly called!")
ValueError: DataFrame constructor not properly called!
From my understanding, I guess you need to iterate over the pages and get the text from each page. can you try the following:
import nltk
pdfreader = PyPDF2.PdfFileReader(open('C:/Users/Novilia/PycharmProjects/tesaja/' + f.filename, 'rb'))
page_contents = [sent for page_no in range(pdfreader.getNumPages())
for sent in nltk.sent_tokenize(pdfreader.getPage(page_no).extractText())]
df1 = DataFrame(page_contents, columns=['isi1'])
Kindly let me know if you find any problem with the code.
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()