请帮帮我,我遇到了cloudinary上传错误。 问题是这个函数在本地主机上运行得很好,但是在pythonanwhere服务器上部署之后就不行了。 使用:
我的代码:
from flask import Flask, render_template, request, redirect, url_for, \
flash, jsonify, make_response
from flask import session as login_session # to avoid confusion with DB session
import random
import string
import httplib2
import json
import requests
import content
# Cloudinary API imports
import cloudinary
import cloudinary.uploader
from cloudinary.uploader import upload
import cloudinary.api
from cloudinary.utils import cloudinary_url
CLOUDINARY = {
'cloud_name': 'ainsolence',
'api_key': 'xxxxxxxxxxxxxxxxxxx',
'api_secret': 'xxxxxxxxxxxxxxxxxxxxxxx',
}
cloudinary.config(cloud_name='ainsolence', api_key='xxxxxxxxxxxxxxxxxxxx',
api_secret='xxxxxxxxxxxxxxxxxxxxxxx')
...
# Create route for editCategory function
# Create route for uploadCategoryImage function
@app.route('/catalog/<int:category_id>/edit/upload/', methods=['GET',
'POST'])
def uploadCategoryImage(category_id):
if 'username' not in login_session or login_session['email'] \
not in ADMIN:
return redirect('/login')
catalog = session.query(Category).all()
categoryToEdit = \
session.query(Category).filter_by(id=category_id).one()
upload_result = None
image_url = None
if request.method == 'POST':
file = request.files['file']
if file:
try:
upload_result = upload(file, use_filename='true',
folder='Menin_zherim/Categories')
print ('This is upload result ' + upload_result)
(image_url, options) = \
cloudinary_url(upload_result['public_id'], format='jpg')
print ('Image url = ' + image_url)
categoryToEdit.image_url = image_url
session.add(categoryToEdit)
session.commit()
flash('Image for category successfully uploaded!')
return redirect(url_for('editCategory',
category_id=category_id, catalog=catalog,
title='Edit category'))
except:
flash('Error in uploading', )
return redirect(url_for('editCategory',
category_id=category_id, catalog=catalog,
title='Edit category'))
else:
return render_template('uploadCategoryImage.html',
category_id=category_id,
catalog=catalog,
category=categoryToEdit,
title='Upload image category')
#In uwsgi file I put this:
#Cloudinary base url
os.environ["CLOUDINARY_URL"] = "CLOUDINARY_URL=cloudinary://blablablabla:XXXXXXXXXXXXXXXXXXXX@ainsolence"
PS:当然,我在代码中使用了真正的api密钥和api密钥
在错误.log在我使用try/except之前:
^{pr2}$在错误.log之后:
2016-12-20 08:40:04,836 :Starting new HTTPS connection (1):
api.cloudinary.com
2016-12-20 08:40:12,846 :Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7eff38c6dac8>: Failed to establish a new connection: [Errno 111] Connection refused',)': /v1_1/ainsolence/image/upload
2016-12-20 08:40:12,846 :Starting new HTTPS connection (2): api.cloudinary.com
2016-12-20 08:40:20,845 :Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7eff38c6dc88>: Failed to establish a new connection: [Errno 111] Connection refused',)': /v1_1/ainsolence/image/upload
2016-12-20 08:40:20,846 :Starting new HTTPS connection (3): api.cloudinary.com
2016-12-20 08:40:28,846 :Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7eff38c6dd68>: Failed to establish a new connection: [Errno 111] Connection refused',)': /v1_1/ainsolence/image/upload
2016-12-20 08:40:28,846 :Starting new HTTPS connection (4): api.cloudinary.com
2016-12-20 08:54:31,637 :Starting new HTTPS connection (5): api.cloudinary.com
2016-12-20 08:54:39,689 :Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7eff38c81c88>: Failed to establish a new connection: [Errno 111] Connection refused',)': /v1_1/ainsolence/image/upload
2016-12-20 08:54:39,690 :Starting new HTTPS connection (6): api.cloudinary.com
2016-12-20 08:54:47,689 :Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7eff38c81be0>: Failed to establish a new connection: [Errno 111] Connection refused',)': /v1_1/ainsolence/image/upload
2016-12-20 08:54:47,690 :Starting new HTTPS connection (7): api.cloudinary.com
2016-12-20 08:54:55,689 :Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7eff38c81d68>: Failed to establish a new connection: [Errno 111] Connection refused',)': /v1_1/ainsolence/image/upload
2016-12-20 08:54:55,690 :Starting new HTTPS connection (8): api.cloudinary.com
请帮助我,如果你有任何建议,我可以找到答案或只是我如何理解这个问题
谢谢你 谨致问候 安东
如果您使用免费的PythonAnywhere帐户执行此操作,那么您还没有配置用于使用PythonAnywhere代理进行传出连接的cloudinary库。代理详细信息是
proxy.server:3128
。在相关问题 更多 >
编程相关推荐