Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Apache Flask错误13,权限被拒绝_Python_Apache_Amazon Web Services_Flask - Fatal编程技术网

Python Apache Flask错误13,权限被拒绝

Python Apache Flask错误13,权限被拒绝,python,apache,amazon-web-services,flask,Python,Apache,Amazon Web Services,Flask,我第一次在AWS上使用Apache部署了一个Flask应用程序。HTML页面加载,但是像上传文件、写入文件和读取文件这样的事情似乎不起作用。在下面的示例中,我调用了这个特定函数,该函数写入从URL接收的数据。但是在这里,我禁用了它,代码只需要读取已经存在的文件。所以,export_po_list.xml已经存在了,我已经从终端检查过了。同样的代码在我的PC中本地运行良好 正在检查/var/log/apache2/error.log 我使用chmod 777-R对包含这个flask应用程序的整个文

我第一次在AWS上使用Apache部署了一个Flask应用程序。HTML页面加载,但是像上传文件、写入文件和读取文件这样的事情似乎不起作用。在下面的示例中,我调用了这个特定函数,该函数写入从URL接收的数据。但是在这里,我禁用了它,代码只需要读取已经存在的文件。所以,export_po_list.xml已经存在了,我已经从终端检查过了。同样的代码在我的PC中本地运行良好

正在检查/var/log/apache2/error.log

我使用chmod 777-R对包含这个flask应用程序的整个文件夹进行了修改。它仍然不起作用

 def po_data(a,b,c):

    array0 = []
    array1 = []
    array2 = []
    array3 = []
    array4 = []
    array5 = []
    array6 = []
    array7 = []
    array8 = []
    array9 = []
    array10 = []
    array11 = []
    array12 = []
    array13 = []
    array14 = []
    array15 = []
    array16 = []
    array17 = []
    array18 = []
    array19 = []
    array20 = []

    url_begin = "https://34.239.8.24:44300/sap/opu/odata/sap/ZRECEASY_ALL_OPEN_PO_SRV/ZRECEASY_ALL_OPEN_POSet?$filter=ImBstyp eq '"
    url_mid_1 = "' and ImBsart eq '"
    url_mid_2 = "' and ImErnam eq '"
    url_end = "'"
    final_url = url_begin + a + url_mid_1 + b + url_mid_2 + c + url_end
    print "\n\n"
    print final_url
    print "\n\n"
    auth_get_po_data ='S4H_FIN','Welcome1'
    headers_get_po_data = {"Content-type":'application/json;charset=utf-8'}
    final_url = "https://34.239.8.24:44300/sap/opu/odata/sap/ZRECEASY_ALL_OPEN_PO_SRV/ZRECEASY_ALL_OPEN_POSet?$filter=ImBstyp eq 'F' and ImBsart eq 'NB' and ImErnam eq 'S4H_MM'"

    #Post data back
    # final_url = "https://34.239.8.24:44300/sap/opu/odata/sap/ZRECEASY_ALL_OPEN_PO_SRV/ZRECEASY_ALL_OPEN_POSet?
   # r_get_po_data = requests.get(final_url,headers=headers_get_po_data,auth=auth_get_po_data, verify=False)
   # print r_get_po_data.text
    print os.getcwd()

# Write temporary XML file to work on parsing
#   file = open('export_po_list.xml', 'w')
#   file.write(r_get_po_data.text)
#   file.close()

# Read XML file
    print os.getcwd()
    tree = ET.parse('export_po_list.xml')
    root = tree.getroot()

#Extract relevant info
    for child in root:
        for child2 in child:
            for child3 in child2:
                counter = 1
                for child4 in child3:
                    # 5 24
                    if (counter == 5):
                        array0.append(str(child4.text))
                    elif (counter == 6):
                        array1.append(str(child4.text))
                    elif (counter == 7):
                        array2.append(str(child4.text))
                    elif (counter == 8):
                        array3.append(str(child4.text))
                    elif (counter == 9):
                        array4.append(str(child4.text))
                    elif (counter == 10):
                        array5.append(str(child4.text))
                    elif (counter == 11):
                        array6.append(str(child4.text))
                    elif (counter == 12):
                        array7.append(str(child4.text))
                    elif (counter == 13):
                        array8.append(str(child4.text))
                    elif (counter == 14):
                        array9.append(str(child4.text))
                    elif (counter == 15):
                        array10.append(str(child4.text))
                    elif (counter == 16):
                        array11.append(str(child4.text))
                    elif (counter == 17):
                        array12.append(str(child4.text))
                    elif (counter == 18):
                        array13.append(str(child4.text))
                    elif (counter == 19):
                        array14.append(str(child4.text))
                    elif (counter == 20):
                        array15.append(str(child4.text))
                    elif (counter == 21):
                        array16.append(str(child4.text))
                    elif (counter == 22):
                        array17.append(str(child4.text))
                    elif (counter == 23):
                        array18.append(str(child4.text))
                    elif (counter == 24):
                        array19.append(str(child4.text))
                    elif (counter == 25):
                        array20.append(str(child4.text))
                    counter = counter + 1

    return array0, array1, array2, array3, array4, array5, array6, array7, array8, array9, array10, array11, array12, array13, array14, array15, array16, array17, array18, array19, array20

不要为文件使用相对路径名,您需要计算绝对路径并确保该位置为可写目录。这是必要的,因为Apache的当前工作目录通常是根目录,而根目录对于代码运行时的用户是不可写的

有关更多详细信息,请参阅mod_wsgi文档,网址为:


将777-R设置为权限是非常糟糕的做法,尤其是在服务器上!有关正确设置,请参阅此答案。不要以root用户身份运行它。如果您在远程服务器上运行它,您应该
ssh
进入它并验证权限。您需要为用户提供所需的权限,并确保
ps u
列出了服务器进程。再次确保您的
export\u po\u list.xml
属于适当的用户并具有读取权限。这是一种什么样的部署?我的意思是EC2、BeansTalk?用户、组和mod perms都必须足够宽松。apache通常要求将该组设置为
http
os.getcwd()
打印什么?
 def po_data(a,b,c):

    array0 = []
    array1 = []
    array2 = []
    array3 = []
    array4 = []
    array5 = []
    array6 = []
    array7 = []
    array8 = []
    array9 = []
    array10 = []
    array11 = []
    array12 = []
    array13 = []
    array14 = []
    array15 = []
    array16 = []
    array17 = []
    array18 = []
    array19 = []
    array20 = []

    url_begin = "https://34.239.8.24:44300/sap/opu/odata/sap/ZRECEASY_ALL_OPEN_PO_SRV/ZRECEASY_ALL_OPEN_POSet?$filter=ImBstyp eq '"
    url_mid_1 = "' and ImBsart eq '"
    url_mid_2 = "' and ImErnam eq '"
    url_end = "'"
    final_url = url_begin + a + url_mid_1 + b + url_mid_2 + c + url_end
    print "\n\n"
    print final_url
    print "\n\n"
    auth_get_po_data ='S4H_FIN','Welcome1'
    headers_get_po_data = {"Content-type":'application/json;charset=utf-8'}
    final_url = "https://34.239.8.24:44300/sap/opu/odata/sap/ZRECEASY_ALL_OPEN_PO_SRV/ZRECEASY_ALL_OPEN_POSet?$filter=ImBstyp eq 'F' and ImBsart eq 'NB' and ImErnam eq 'S4H_MM'"

    #Post data back
    # final_url = "https://34.239.8.24:44300/sap/opu/odata/sap/ZRECEASY_ALL_OPEN_PO_SRV/ZRECEASY_ALL_OPEN_POSet?
   # r_get_po_data = requests.get(final_url,headers=headers_get_po_data,auth=auth_get_po_data, verify=False)
   # print r_get_po_data.text
    print os.getcwd()

# Write temporary XML file to work on parsing
#   file = open('export_po_list.xml', 'w')
#   file.write(r_get_po_data.text)
#   file.close()

# Read XML file
    print os.getcwd()
    tree = ET.parse('export_po_list.xml')
    root = tree.getroot()

#Extract relevant info
    for child in root:
        for child2 in child:
            for child3 in child2:
                counter = 1
                for child4 in child3:
                    # 5 24
                    if (counter == 5):
                        array0.append(str(child4.text))
                    elif (counter == 6):
                        array1.append(str(child4.text))
                    elif (counter == 7):
                        array2.append(str(child4.text))
                    elif (counter == 8):
                        array3.append(str(child4.text))
                    elif (counter == 9):
                        array4.append(str(child4.text))
                    elif (counter == 10):
                        array5.append(str(child4.text))
                    elif (counter == 11):
                        array6.append(str(child4.text))
                    elif (counter == 12):
                        array7.append(str(child4.text))
                    elif (counter == 13):
                        array8.append(str(child4.text))
                    elif (counter == 14):
                        array9.append(str(child4.text))
                    elif (counter == 15):
                        array10.append(str(child4.text))
                    elif (counter == 16):
                        array11.append(str(child4.text))
                    elif (counter == 17):
                        array12.append(str(child4.text))
                    elif (counter == 18):
                        array13.append(str(child4.text))
                    elif (counter == 19):
                        array14.append(str(child4.text))
                    elif (counter == 20):
                        array15.append(str(child4.text))
                    elif (counter == 21):
                        array16.append(str(child4.text))
                    elif (counter == 22):
                        array17.append(str(child4.text))
                    elif (counter == 23):
                        array18.append(str(child4.text))
                    elif (counter == 24):
                        array19.append(str(child4.text))
                    elif (counter == 25):
                        array20.append(str(child4.text))
                    counter = counter + 1

    return array0, array1, array2, array3, array4, array5, array6, array7, array8, array9, array10, array11, array12, array13, array14, array15, array16, array17, array18, array19, array20