สอบถาม ทำ web service แล้วเอาไปไว้บน sevser มัน errorครับ

แนะนำ สอบถาม ภาษา C สำหรับผู้เริ่มต้น ภาษา Java ภาษา Python

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
jirawoot
PHP VIP Members
PHP VIP Members
โพสต์: 3129
ลงทะเบียนเมื่อ: 17/06/2019 10:30 am

สอบถาม ทำ web service แล้วเอาไปไว้บน sevser มัน errorครับ

โพสต์ที่ยังไม่ได้อ่าน โดย jirawoot »

ทำ web service แล้วเอาไปไว้บน sevser มัน errorครับ
โค้ดerror

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

/usr/bin/python: can't find '__main__' module in '/htmltoPdfImage'
root@ubuntu-2gb-sgp1-01:~# python /htmltoPdfImage/index.py
Traceback (most recent call last):
File "/htmltoPdfImage/index.py", line 2, in <module>
from flask_httpauth import HTTPBasicAuth
ImportError: No module named flask_httpauth
root@ubuntu-2gb-sgp1-01:~#
โค้ดโปรแกรม

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

from flask import Flask, render_template, request
from flask_httpauth import HTTPBasicAuth
from flask import send_file
import subprocess
import os.path
import psycopg2 as p
con=None

base_store_pathpdf = '/home/com001/PycharmProjects/htmltoPdfImage2/pdf'
base_store_pathjpg = '/home/com001/PycharmProjects/htmltoPdfImage2/jpg'

app =Flask(__name__)
auth = HTTPBasicAuth()

try:
    con=p.connect(host='localhost', database='test', user='postgres')
    cur=con.cursor()
    sql="""SELECT * FROM "user";"""
    sql=sql.encode('utf-8')
    cur.execute(sql)
    resufts=cur.fetchall()
    users={}
    for row in resufts:
        users[row[3]]=row[4]


except p.DatabaseError:
    print('Error : %s'%p.DatabaseError)
if con:
    con.close()

@auth.get_password
def get_pw(username):
    if username in users:
        return users.get(username)
    return None

@app.route('/')
# @auth.login_required
def index():
    username=auth.username()
    return render_template('test.html', username=username)

@app.route('/view/<int:typefile>/<string:filename>/<path:linkurl>',methods=['GET'])
@auth.login_required
def convpdf(typefile,filename,linkurl):


    filename = filename.strip()
    linkurl = linkurl.strip()
    typefile = 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
        response = send_file(path_sh)
        response.headers['Content-Type'] = 'application/pdf'
        response.headers['Content-Disposition'] = 'inline; filename=%s.pdf' % filename
        return response

    elif typefile == 2:
        str = filename + '.jpg'
        global base_store_pathjpg
        path_bin = 'wkhtmltoimage'
        path = os.path.join(base_store_pathjpg, str)
        subprocess.call([path_bin, linkurl, path])
        path_sh = 'jpg/' + str
        response = send_file(path_sh)
        response.headers['Content-Type'] = 'image/jpg'
        response.headers['Content-Disposition'] = 'inline; filename=%s.jpg' % filename
        return response

if __name__ == '__main__':
   app.run(debug=True)
tatiya
PHP VIP Members
PHP VIP Members
โพสต์: 2845
ลงทะเบียนเมื่อ: 09/07/2018 9:35 am

Re: สอบถาม ทำ web service แล้วเอาไปไว้บน sevser มัน errorครับ

โพสต์ที่ยังไม่ได้อ่าน โดย tatiya »

ใน Error บอกว่าไม่พบ module flask_httpauth
ลอง

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

pip install flask_httpauth
ได้เลยครับ
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 99