首页 文章

对本地.py脚本的Ajax调用工作正常,直到我在顶部添加一个简单的导入,它失败并出现500错误

提问于
浏览
0

这一切都发生在Django平台上 . 这是我的ajax电话:

$.ajax({
        type: 'GET',
        url: 'get-dropdown-contents', //a url mapping to controller_ajax.py
        dataType:'json',
        data: {'selection_path': selectionPath},
        success: function (data) {
               //blah blah blah.... it doesn't reach here

这是被调用的.py脚本:

from hs_restclient import HydroShare, HydroShareAuthBasic
from django.http import JsonResponse
from functions import irods_query


def get_dropdown_contents(request):
    print "Entered"
    if request.method == 'GET':
        selection_path = request.GET['selection_path']
        irods_data = irods_query(selection_path)
        return JsonResponse({
                                'success': "Response successfully returned!",
                                'irods_data': irods_data
                            })


def upload_to_hydroshare(request):
    if request.method == 'GET':
        hydro_username = request.GET['hydro_username']
        hydro_password = request.GET['hydro_password']
        try:
            print hydro_password
            print hydro_username
            hs = HydroShare(auth=HydroShareAuthBasic(username='joe', password='shmoe'))
        except Exception, err:
            print "Err: " + str(err)
            return JsonResponse({'error': 'Username or password invalid'})
        return JsonResponse({'success': 'Response successfully returned!'})

调用get_dropdown_contents()函数的ajax调用完全正常 . 但是,通过简单地添加 from hs_resclient import ...语句,ajax调用现在失败,出现500内部服务器错误 . 如果我注释掉那个语句,那么这个调用没有问题 . 我无法弄清楚为什么我的生活 .

有任何想法吗?

2 回答

  • 1

    尝试添加

    import cgitb
    cgitb.enable()
    

    到python文件的顶部 . 这应该在发生内部服务器错误时将回溯重定向到浏览器,并为您提供更多信息 . 请记得将其删除以进行 生产环境 .

  • 0

    我在Web服务器上遇到了类似的问题,因为当我创建新文档时,他们没有正确的读/写/执行权限 . 这可能是您尝试包含的文档的问题吗?你需要在ajax调用中将“py”文件扩展名包含在文件名中吗?

    $.ajax({
            type: 'GET',
            url: 'get-dropdown-contents.py', //a url mapping to controller_ajax.py
            dataType:'json',
            data: {'selection_path': selectionPath},
            success: function (data) {
                   //blah blah blah.... it doesn't reach here
    

相关问题