from flask import Flask, render_template, make_response
import pdfkit
app = Flask(__name__)
#app.route('/<Customer_Full_Name>/<Customer_adress>/<customerID_number>/<CurrentDate>/<Digital_Signature>')
def pdf_template(Customer_Full_Name, Customer_adress, customerID_number,CurrentDate,Digital_Signature):
rendered = render_template('pdf_template.html', Customer_Full_Name=Customer_Full_Name,Customer_adress=Customer_adress,customerID_number=customerID_number, CurrentDate=CurrentDate, Digital_Signature=Digital_Signature)
pdf = pdfkit.from_string(rendered)
response = make_response(pdf, False)
response.headers['Content-Type'] = 'application/pdf'
response.headers['Content-Disposition'] = 'inline;filename=output'
return response
# return render_template('pdf_template.html')
if __name__ == '__main__':
app.run(debug=True)
127.0.0.1 - - [11/Nov/2021 16:56:58] "GET /Customer_Fl_Name/Customedress/customD_number/CurntDate/Dil_Signature HTTP/1.1" 500 -
flask run output:
* Serving Flask app 'app.py' (lazy loading)
* 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
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[2021-11-11 16:58:20,679] ERROR in app: Exception on /Customer_Fl_Name/Customedress/customD_number/CurntDate/Dil_Signature [GET]
Traceback (most recent call last):
File "/Users/swapnil/Desktop/Clinsj_Certificate/venv/lib/python3.7/site-packages/flask/app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "/Users/swapnil/Desktop/Clinsj_Certificate/venv/lib/python3.7/site-packages/flask/app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/swapnil/Desktop/Clinsj_Certificate/venv/lib/python3.7/site-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/swapnil/Desktop/Clinsj_Certificate/venv/lib/python3.7/site-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/Users/swapnil/Desktop/Clinsj_Certificate/app.py", line 11, in pdf_template
pdf = pdfkit.from_string(rendered, False)
File "/Users/swapnil/Desktop/Clinsj_Certificate/venv/lib/python3.7/site-packages/pdfkit/api.py", line 72, in from_string
return r.to_pdf(output_path)
File "/Users/swapnil/Desktop/Clinsj_Certificate/venv/lib/python3.7/site-packages/pdfkit/pdfkit.py", line 156, in to_pdf
raise IOError('wkhtmltopdf reported an error:\n' + stderr)
OSError: wkhtmltopdf reported an error:
Loading pages (1/6)
Warning: Blocked access to file
Warning: Blocked access to file
Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol "about" is unknown
Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol "about" is unknown
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done
Exit with code 1 due to network error: ProtocolUnknownError
You should try to add this option:
"enable-local-file-access": ""
to your options dict
Stephane
Related
I ran the following python sample code on this page (you need a private key to run this): https://cloud.google.com/speech-to-text/docs/quickstart-client-libraries
# Imports the Google Cloud client library
from google.cloud import speech
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'key.json'
# Instantiates a client
client = speech.SpeechClient()
# The name of the audio file to transcribe
gcs_uri = "gs://cloud-samples-data/speech/brooklyn_bridge.raw"
audio = speech.RecognitionAudio(uri=gcs_uri)
config = speech.RecognitionConfig(
encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=16000,
language_code="en-US",
)
# Detects speech in the audio file
response = client.recognize(config=config, audio=audio)
for result in response.results:
print("Transcript: {}".format(result.alternatives[0].transcript))
This results in the following error:
Traceback (most recent call last):
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\grpc_helpers.py", line 57, in error_remapped_callable
return callable_(*args, **kwargs)
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\grpc\_channel.py", line 826, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\grpc\_channel.py", line 729, in _end_unary_response_blocking
raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "failed to connect to all addresses"
debug_error_string = "{"created":"#1614347442.192000000","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":4090,"referenced_errors":[{"created":"#1614347442.192000000","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":394,"grpc_status":14}]}"
>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\retry.py", line 184, in retry_target
return target()
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\grpc_helpers.py", line 59, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.ServiceUnavailable: 503 failed to connect to all addresses
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/Users/98274/Desktop/carla_ppo/test_connection.py", line 22, in <module>
response = client.recognize(config=config, audio=audio)
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\cloud\speech_v1\services\speech\client.py", line 334, in recognize
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\gapic_v1\method.py", line 145, in __call__
return wrapped_func(*args, **kwargs)
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\retry.py", line 286, in retry_wrapped_func
on_error=on_error,
File "C:\Users\98274\anaconda3\envs\carla\lib\site-packages\google\api_core\retry.py", line 206, in retry_target
last_exc,
File "<string>", line 3, in raise_from
google.api_core.exceptions.RetryError: Deadline of 120.0s exceeded while calling functools.partial(<function _wrap_unary_errors.<locals>.error_remapped_callable at 0x0000026B56606A68>, config {
encoding: LINEAR16
sample_rate_hertz: 16000
language_code: "en-US"
}
audio {
uri: "gs://cloud-samples-data/speech/brooklyn_bridge.raw"
}
, metadata=[('x-goog-api-client', 'gl-python/3.7.9 grpc/1.31.0 gax/1.23.0 gapic/2.0.1')]), last exception: 503 failed to connect to all addresses
What's the problem? Does it related to internet issue because I am in China? How can I solve it?
I am posting the answer as CommunityWiki to further contribuite to the community.
As discussed in the comment section, the code provided in the documentation is running smoothly. However, you have to make sure that you set your credentials using GOOGLE_APPLICATION_CREDENTIALS so your request is authenticated. Also,the client libraries have to be properly installed.
In #antaressgzz case's the request to the API was being blocked by a firewall rule. Thus, it is a good practice to check these rules, changing them if applicable.
I wrote a python program as to [Ph Num 1 <-> Twilio Server <-> Ph Num2 ]
[- Send a Message from my ph number (Num 1) containing another phone number(Num 2) to twilio server
- twilio takes the number (Num2) and calls me back (Num1) (saying as you are about to conference) and
- twilio calls the Num 2 and conferences me (Num1)
Here is my program:
from flask import Flask, request
from twilio import twiml
from twilio.rest import Client
app = Flask(__name__)
account = "AC7d2a***************"
token = "f83b27**************"
client = Client(account, token)
#app.route("/sms", methods=['GET', 'POST'])
def sms():
number=request.form["From"]
call= client.calls.create(from_="+1857*******",to=number,url="https://handler.twilio.com/twiml/EHb330731ab2c9a35fcdc620bef1b88536")
return str(resp)
if __name__=="__main__":
app.run()
The url="https://handler.twilio.com/twiml/EHb330731ab2c9a35fcdc620bef1b88536 contains
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>You are about to enter a conference</Say>
<Dial><Conference>number</Conference></Dial>
</Response>
i did Ngrok too and added my Ngrok link in Voice and Message URL in twilio number
I tried many changes and getting all kind of error instead of twilio number calling me after sending a message(with Ph Number (Num2) to conference)
Recent error while executing the above code is
Error:
[2017-11-13 09:46:41,570] ERROR in app: Exception on /sms [POST]
Traceback (most recent call last):
File "/home/arif/my_app/local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/home/arif/my_app/local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/arif/my_app/local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/arif/my_app/local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/home/arif/my_app/local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "conf.py", line 17, in sms
return str(resp)
NameError: global name 'resp' is not defined
127.0.0.1 - - [13/Nov/2017 09:46:41] "POST /sms HTTP/1.1" 500 -
Does my program get the result what i expected ? Can anyone help me where is the issue is ?
Twilio developer evangelist here.
There are a couple of issues here. First up, you are getting an error in your webhook response. You can see the error at the bottom of your stack trace:
File "conf.py", line 17, in sms
return str(resp)
NameError: global name 'resp' is not defined
127.0.0.1 - - [13/Nov/2017 09:46:41] "POST /sms HTTP/1.1" 500 -
It says that resp is not defined.
You can see that within your method, you never define a resp but you try to return the str version of it:
def sms():
number=request.form["From"]
call= client.calls.create(from_="+1857*******",to=number,url="https://handler.twilio.com/twiml/EHb330731ab2c9a35fcdc620bef1b88536")
return str(resp)
You can just return an empty string to Twilio in this case.
def sms():
number=request.form["From"]
call= client.calls.create(from_="+1857*******",to=number,url="https://handler.twilio.com/twiml/EHb330731ab2c9a35fcdc620bef1b88536")
return ('', 204)
Once that is fixed you'll find you are only making one call, the outgoing call back to yourself. To conference with the number that you want to call, you will need to generate two calls. You say that the body of the message that you are sending will be the other number you want to dial into the conference, so this should work:
def sms():
my_number=request.form["From"]
other_number=request.form["Body"]
twilio_number="+1857*******"
conference_url="https://handler.twilio.com/twiml/EHb330731ab2c9a35fcdc620bef1b88536"
client.calls.create(from_=twilio_number,to=my_number,url=conference_url)
client.calls.create(from_=twilio_number,to=other_number,url=conference_url)
return ('', 204)
Let me know if that helps.
I recently added sentry for error tracking in my project and configure raven according to documentation here but getting the error shown below.
settings.py
import raven
INSTALLED_APPS = [
# 3rd party app
'raven.contrib.django.raven_compat',
]
RAVEN_CONFIG = {
'dsn': 'https://*****#sentry.io/224093',
'release': raven.fetch_git_sha(os.path.dirname(os.pardir)),
}
Error Log
System check identified no issues (0 silenced).
October 02, 2017 - 11:31:58
Django version 1.10, using settings 'FoodCham.settings.development'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Sending message of length 2240 to https://sentry.io/api/224093/store/
Internal Server Error: /
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 39, in inner
response = get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 244, in _legacy_get_response
response = middleware_method(request)
File "/usr/local/lib/python2.7/dist-packages/raven/contrib/django/middleware/__init__.py", line 135, in process_request
request.body # forces stream to be read into memory
File "/usr/local/lib/python2.7/dist-packages/django/http/request.py", line 267, in body
int(self.META.get('CONTENT_LENGTH', 0)) > settings.DATA_UPLOAD_MAX_MEMORY_SIZE):
ValueError: invalid literal for int() with base 10: ''
Internal Server Error: /
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 39, in inner
response = get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 244, in _legacy_get_response
response = middleware_method(request)
File "/usr/local/lib/python2.7/dist-packages/raven/contrib/django/middleware/__init__.py", line 135, in process_request
request.body # forces stream to be read into memory
File "/usr/local/lib/python2.7/dist-packages/django/http/request.py", line 267, in body
int(self.META.get('CONTENT_LENGTH', 0)) > settings.DATA_UPLOAD_MAX_MEMORY_SIZE):
ValueError: invalid literal for int() with base 10: ''
[02/Oct/2017 11:32:04] "GET / HTTP/1.1" 500 69274
Any helpful answer will be appreciated!
It's a bug with a Django version. I had Django 1.10 installed and was seeing this error. Upgrading to 1.10.8 as mentioned in the issue solved the problem.
It's a bug in Django not in raven which is solved in Django 1.10.8, by just upgrading django-1.10 to django-1.10.8 it works fine.
I'm sure this is my fault, but my system has been working for months and now does not work. I've looked in Django docs and here on stackoverflow, and I understand the issue that 'connection refused' means nobody is listening on the socket; but I don't understand why, and don't know how to go forward.
I use Vagrant + VirtualBox on a MacPro, and for six months I have been able to create virtual machines and run my app with no problems. I have some VM's where everything works as expected.
On my newly-created Vagrant VM's, I install and configure my django apps and run them using 'python manage.py runserver --settings=mumble.settings.py 0.0.0.0:8000'. Note that this is Django 1.8.3, but again,it works fine on some VM's.
For mysterious reasons, when I create a new vagrant VM and install my django payload (using deploy scripts that haven't changed), and connect to the django server, I get Errno 111 Connection refused:
+ python ./manage.py runserver --settings=mydjango.settings 0.0.0.0:8000
.....
_d^^^^^^^^^b_
.d'' ``b.
.p' `q.
.d' `b.
.d' `b. * Mezzanine 4.0.1
:: :: * Django 1.8.3
:: M E Z Z A N I N E :: * Python 2.7.12
:: :: * MySQL 5.7.18
`p. .q' * Linux 4.4.0-75-generic
`p. .q'
`b. .d'
`q.. ..p'
^q........p^
''''
Performing system checks...
System check identified no issues (0 silenced).
May 31, 2017 - 09:50:50
Django version 1.8.3, using settings 'mydjango.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 189, in __call__
response = self.get_response(request)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 204, in get_response
'request': request
File "/usr/lib/python2.7/logging/__init__.py", line 1185, in error
Log 'msg % args' with severity 'ERROR'.
File "/usr/lib/python2.7/logging/__init__.py", line 1193, in error
self._log(ERROR, msg, args, **kwargs)
File "/usr/lib/python2.7/logging/__init__.py", line 1286, in _log
self.handle(record)
File "/usr/lib/python2.7/logging/__init__.py", line 1296, in handle
self.callHandlers(record)
File "/usr/lib/python2.7/logging/__init__.py", line 1336, in callHandlers
hdlr.handle(record)
File "/usr/lib/python2.7/logging/__init__.py", line 759, in handle
self.emit(record)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/utils/log.py", line 129, in emit
self.send_mail(subject, message, fail_silently=True, html_message=html_message)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/utils/log.py", line 132, in send_mail
mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 98, in mail_admins
mail.send(fail_silently=fail_silently)
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/message.py", line 303, in send
return self.get_connection(fail_silently).send_messages([self])
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
new_conn_created = self.open()
File "/vagrant/repos_here/www.mydjango.org/venv/www/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 58, in open
self.connection = connection_class(self.host, self.port, **connection_params)
File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 291, in _get_socket
return socket.create_connection((host, port), timeout)
File "/usr/lib/python2.7/socket.py", line 575, in create_connection
raise err
error: [Errno 111] Connection refused
[31/May/2017 09:50:55]"GET /donate/ HTTP/1.1" 500 59
Things I know:
'python ./manage.py' with no arguments will run fine, and shows the help message.
All forms of addressing the web server will fail:
curl http://localhost:8000
curl http://127.0.0.1:8000
curl http://192.168.33.10:8000
from a browser: http://192.168.33.10:8000
nginx is serving on port 80, no problem
my database is a copy of the production database, and it looks fine through 'mysql'
And here is a weird thing: I brought down the Django tutorial, used the 'runserver' command, and it worked!
[vagrant][~/tmp/django_tutorial/mysite]
$ python manage.py runserver 0.0.0.0:8000
Performing system checks...
System check identified no issues (0 silenced).
May 30, 2017 - 20:36:44
Django version 1.8.3, using settings 'mysite.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
[30/May/2017 20:37:05]"GET / HTTP/1.1" 200 1767
Any suggestions on how to debug this?
The answer has nothing to do with my environment. My co-worker added a name to settings.ADMINS, which had been an empty list before that. When ADMINS is a non-empty list, any error triggers an attempt to send email to all of the email addresses in ADMINS, and my VM was not configured to send email. This is documented but not emphasized. The problem did not happen to my coworker, because that associated changes did not trigger a server error.
I am new to neo4j and want it to connect with Python. I am using neo4j version 3.0.3 and following this tutorial.
I put the code below in my Python file, I have changed the password, since my password is root:
from neo4j.v1 import GraphDatabase, basic_auth
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth(user = "neo4j", password = "root"))
session = driver.session()
session.run("CREATE (a:Person {name:'Bob'})")
result = session.run("MATCH (a:Person) RETURN a.name AS name")
for record in result:
print(record["name"])
session.close()
But on running it, I am getting following errors:
Traceback (most recent call last):
File "D:/Work/MySQL_neo4j_Importer/dumping_ingredients.py", line 3, in <module>
session = driver.session()
File "C:\Python27\lib\site-packages\neo4j\v1\session.py", line 148, in session
session = Session(self)
File "C:\Python27\lib\site-packages\neo4j\v1\session.py", line 461, in __init__
self.connection = connect(driver.host, driver.port, driver.ssl_context, **driver.config)
File "C:\Python27\lib\site-packages\neo4j\v1\connection.py", line 403, in connect
s = create_connection((host, port))
File "C:\Python27\lib\socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11004] getaddrinfo failed
I have also tried this StackOverFlow answer as well, but, the result remains same.
For Neo4j 1.8 / 1.9 / 2.0 / 2.1 / 2.2 / 2.3 you could use Py2neo.
Here you can find an exhaustive list of python drivers