1
我有一個Flask應用程序,它監聽傳入的Shopify webhooks,執行某些操作並響應200.但是,Shopify一直髮送webhook,就好像我的應用程序以200以外的響應。Shopify不停止發送webhook Flask應用程序
當我模擬這個,捲曲:
curl -H "Content-Type: application/json" -D /tmp/dump.log -X POST -d @<valid json> <my server>
響應標題是:
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Thu, 16 Apr 2015 09:25:23 GMT
Server: Apache/2.4.7 (Ubuntu)
Content-Length: 0
Content-Type: text/html; charset=utf-8
我認爲,第一100 Continue
是世界衛生大會t使Shopify認爲我的應用程序失敗。我在本地實例和生產環境中獲得了相同的響應。
這是怎麼回事,我該如何解決?
編輯
這裏的Python代碼來處理請求
import json
from flask_mail import Mail, Message
from pyPdf import PdfFileWriter, PdfFileReader
from flask import Flask
from certificate import Certificate
from flask import request
from purchase import Purchase
from stars import Stars
app = Flask(__name__)
app.config.from_envvar('NAMESTAR_SETTINGS')
app.config["MAIL_SERVER"] = 'smtp.sendgrid.net'
app.config["MAIL_PORT"] = 587
app.config["MAIL_USERNAME"] = app.config.get('EMAIL_LOGIN')
app.config["MAIL_PASSWORD"] = app.config.get('EMAIL_PASSWORD')
app.config["MAIL_DEFAULT_SENDER"] = app.config.get('SENDER')
app.config["PATH"] = app.config.get('PATH')
ADMINS = app.config.get('ADMINS')
mail = Mail(app)
def get_request():
if request.args.get('hyg') is not None:
return int(request.args.get('hyg'))
else:
return request.data
#returns an instance of Purchase class based on the request
def get_purchase():
pass
#creates and saves a PDF created with reportlab
def generate_certificate(purchase):
pass
#sends the generated PDF to the recipient
def send_email(certificate_path, recipient, name=""):
msg = Message("Message", recipients=[recipient])
with app.open_resource(certificate_path) as fp:
msg.attach("certificate.pdf", "application/pdf", fp.read())
f = open(app.config.get('PATH') + "/email_templates/certificate", "r")
html = f.read()
msg.html = html % (name)
mail.send(msg)
@app.route('/', methods=['GET', 'POST'])
def generate():
try:
purchase = get_purchase()
certificate_path = generate_certificate(purchase)
send_email(certificate_path, purchase.customer_email(), name=purchase.customer_name())
except Exception as e:
raise
return ('', 200)
if __name__ == '__main__':
app.debug = False
app.run(debug=False)
服務器是Apache的,這裏是爲應用程序
<VirtualHost *:80>
DocumentRoot /var/www/namestar/current
WSGIDaemonProcess namestar user=www-data group=www-data threads=5
WSGIScriptAlias//var/www/namestar/current/namestar.wsgi
<Directory /var/www/namestar/current>
WSGIScriptReloading On
WSGIProcessGroup namestar
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
SetEnv NAMESTAR_SETTINGS="/var/www/namestar/current/config/production.cfg"
</VirtualHost>
虛擬主機設置
請[edit]包含處理此請求的視圖函數。 – davidism
現在編輯,有什麼想法? –