สอบถาม เกี่ยวกับการ dump ค่าใน obj ออกมาดูต้องทำอยางไรครับ

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: สอบถาม เกี่ยวกับการ dump ค่าใน obj ออกมาดูต้องทำอยางไรครับ

Re: สอบถาม เกี่ยวกับการ dump ค่าใน obj ออกมาดูต้องทำอยางไรครับ

โดย jirawoot » 04/07/2019 10:06 am

สามารถใช้คำสั่ง for loop วนค่าเอามาดูโดยใช้โค้ดนี้

โค้ด: เลือกทั้งหมด

for attr in dir(response):
    print("obj.%s = %r" % (attr, getattr(response, attr)))

สอบถาม เกี่ยวกับการ dump ค่าใน obj ออกมาดูต้องทำอยางไรครับ

โดย jirawoot » 03/07/2019 10:11 am

ผมดูค่าในตัวแปร response ออกมาดู มีวิธีไหนบ้างครับ ผมลอง ใช้ print แล้วมัน error ครับ
Selection_012.png
Selection_012.png (28.41 KiB) Viewed 567 times
โค้ด error

โค้ด: เลือกทั้งหมด

TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.

Traceback (most recent call last)
File "/home/com001/PycharmProjects/htmltoPdfImage2/venv/lib/python3.6/site-packages/flask/app.py", line 2328, in __call__
return self.wsgi_app(environ, start_response)
File "/home/com001/PycharmProjects/htmltoPdfImage2/venv/lib/python3.6/site-packages/flask/app.py", line 2314, in wsgi_app
response = self.handle_exception(e)
File "/home/com001/PycharmProjects/htmltoPdfImage2/venv/lib/python3.6/site-packages/flask/app.py", line 1760, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/com001/PycharmProjects/htmltoPdfImage2/venv/lib/python3.6/site-packages/flask/_compat.py", line 36, in reraise
raise value
File "/home/com001/PycharmProjects/htmltoPdfImage2/venv/lib/python3.6/site-packages/flask/app.py", line 2311, in wsgi_app
response = self.full_dispatch_request()
File "/home/com001/PycharmProjects/htmltoPdfImage2/venv/lib/python3.6/site-packages/flask/app.py", line 1835, in full_dispatch_request
return self.finalize_request(rv)
File "/home/com001/PycharmProjects/htmltoPdfImage2/venv/lib/python3.6/site-packages/flask/app.py", line 1850, in finalize_request
response = self.make_response(rv)
File "/home/com001/PycharmProjects/htmltoPdfImage2/venv/lib/python3.6/site-packages/flask/app.py", line 1976, in make_response
'The view function did not return a valid response. The'
TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame
dump(obj) dumps all that's known about the object
โค้ดโปรแกรม

โค้ด: เลือกทั้งหมด

@app.route('/test',methods=['GET'])
def convpdf():
    filename = request.args.get('filename')
    linkurl = request.args.get('linkurl')
    typefile = request.args.get('typefile')
    if typefile == '1':
        str = filename+'.pdf'
        global base_store_pathpdf
        path_bin = 'wkhtmltopdf'
        path = os.path.join(base_store_pathpdf, str)
        subprocess.call([path_bin, linkurl, path])
        path_sh='pdf/'+str
        # pdf = pdfkit.from_url(linkurl, False)
        response = send_file(path_sh)
        print( response)

ข้างบน