为什么在部署Flask应用程序时出现此错误?

时间:2019-05-31 12:02:17

标签: python python-3.x flask web-applications pythonanywhere

我正尝试为小型用途部署小型Web应用程序,并且在部署它时,我在错误日志中收到以下错误。有人可以解释这里发生了什么吗?

我对Web应用程序部署还很陌生,因此,如果有人可以提供一些链接来提高我的知识,那也会有所帮助。

这是我使用的代码:

from flask import Flask, make_response, request
import io
import csv
import os
import sqlite3
import pandas as pd
import requests

app = Flask(__name__)


@app.route('/')
def form():
    return """
        <html>
            <body>
                <h1>Program to find locations corresponding to 1791 lattitudes and longitudes.</h1>
                <h4>Please note that the file should be in csv format anf the data should be in the following format: <u>gps_latitude, gps_longitude</u></h4>

                <form action="/upload_confirm" method="post" enctype="multipart/form-data">
                    <input type="file" name="data_file" accept=".csv">
                    <input type="submit">
                </form>
            </body>
        </html>
    """


@app.route('/upload_confirm', methods=["POST"])
def upload_confirmation():
    f = request.files['data_file']
    if not f:
        return """No file uploaded<br>
                    <form action="/">
                        <input type="submit" value="Retry">
                    </form>"""
    else:
        database=sqlite3.connect("C:\SQLiteStudio\data.db")
        cur=database.cursor()

        task1="""CREATE TABLE IF NOT EXISTS coordinates_table (
       sr_no int,
       gps_latitude DOUBLE PRECISION ,
       gps_longitude DOUBLE PRECISION,
       license_key_allotted VARCHAR
   );"""

        task2="""INSERT INTO coordinates_table (sr_no,gps_latitude,gps_longitude,license_key_allotted) VALUES (?,?,?,?)"""

        cur.execute(task1)

        out=pd.read_csv(f)
        x=out
        if len(out)>1791:
            print("the file has too many coordinate values, would process first 1791 coordinates only")
            data_count=1791
        elif len(out)<199:
            data_count=len(out)
        elif len(out)<398:
            data_count=len(out)
        elif len(out)<597:
            data_count=len(out)
        elif len(out)<796:
            data_count=len(out)
        elif len(out)<995:
            data_count=len(out)
        elif len(out)<1194:
            data_count=len(out)
        elif len(out)<1393:
            data_count=len(out)
        elif len(out)<1592:
            data_count=len(out)
        elif len(out)<1791:
            data_count=len(out)


        row=1
        x=[]
        while row<=199 and row <data_count :
            x=[row,out.iloc[row,0],out.iloc[row,1],"key_1"]
            cur.execute(task2,x)
            database.commit()
            row+=1

        a=row+199

        while row<a and row<data_count:
            x=[row,out.iloc[row,0],out.iloc[row,1],"key_2"]
            cur.execute(task2,x)
            database.commit()
            row+=1

        a=row+199

        while row<a and row<data_count:
            x=[row,out.iloc[row,0],out.iloc[row,1],"key_3"]
            cur.execute(task2,x)
            database.commit()
            row+=1

        a=row+199

        while row<a and row<data_count:
            x=[row,out.iloc[row,0],out.iloc[row,1],"key_4"]
            cur.execute(task2,x)
            database.commit()
            row+=1

        a=row+199

        while row<a and row<data_count:
            x=[row,out.iloc[row,0],out.iloc[row,1],"key_5"]
            cur.execute(task2,x)
            database.commit()
            row+=1

        a=row+199
        while row<a and row<data_count:
            x=[row,out.iloc[row,0],out.iloc[row,1],"key_6"]
            cur.execute(task2,x)
            database.commit()
            row+=1

        a=row+199

        while row<a and row<data_count:
            x=[row,out.iloc[row,0],out.iloc[row,1],"key_7"]
            cur.execute(task2,x)
            database.commit()
            row+=1

        a=row+199

        while row<a and row<data_count:
            x=[row,out.iloc[row,0],out.iloc[row,1],"key_8"]
            cur.execute(task2,x)
            database.commit()
            row+=1

        a=row+199

        while row<data_count:
            x=[row,out.iloc[row,0],out.iloc[row,1],"key_9"]
            cur.execute(task2,x)
            database.commit()
            row+=1


        if len(out)>1791:
            out.drop(out.head(1791).index, inplace=True)
            out.to_csv(f, index=False)



        with open('location_file.csv', mode='a', newline='') as location_file:
            location_writer = csv.writer(location_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)

            cur.execute("""SELECT * FROM coordinates_table""")
            coordinates=cur.fetchall()


            for i in range(len(coordinates)):

                key_check=coordinates[i]

                if key_check[3]=="key_1":

                    a=key_check
                    url = "https://apis.mapmyindia.com/advancedmaps/v1/kgpxta9p6y6zjdxnxh6qcwnke19bx8bt/rev_geocode"
                    querystring = {"lat":a[1],"lng":a[2]}
                    headers = {
                     'cache-control': "no-cache",
                     'postman-token': "e511fc69-0887-9eb7-8865-08b3afd25902"
                         }
                    response = requests.request("POST", url, headers=headers, params=querystring)
                    res=response.text
                    res=ast.literal_eval(res)
                    res=res["results"]
                    res=res[0]
                    res=res["formatted_address"]
                    location_writer.writerow([a[1],a[2],res])


                if key_check[3]=="key_2":
                    a=key_check
                    url = "https://apis.mapmyindia.com/advancedmaps/v1/zo3mglknal8p14y8jnq7m7pyy2vpxaha/rev_geocode"
                    querystring = {"lat":a[1],"lng":a[2]}
                    headers = {
                     'cache-control': "no-cache",
                     'postman-token': "e511fc69-0887-9eb7-8865-08b3afd25902"
                         }
                    response = requests.request("POST", url, headers=headers, params=querystring)
                    res=response.text
                    res=ast.literal_eval(res)
                    res=res["results"]
                    res=res[0]
                    res=res["formatted_address"]
                    location_writer.writerow([a[1],a[2],res])


                if key_check[3]=="key_3":
                    a=key_check
                    url = "https://apis.mapmyindia.com/advancedmaps/v1/aqfz9dx2xbv358yt3v8aia9cfhw97mxg/rev_geocode"
                    querystring = {"lat":a[1],"lng":a[2]}
                    headers = {
                     'cache-control': "no-cache",
                     'postman-token': "e511fc69-0887-9eb7-8865-08b3afd25902"
                         }
                    response = requests.request("POST", url, headers=headers, params=querystring)
                    res=response.text
                    res=ast.literal_eval(res)
                    res=res["results"]
                    res=res[0]
                    res=res["formatted_address"]
                    location_writer.writerow([a[1],a[2],res])


                if key_check[3]=="key_4":

                    a=key_check


                    url = "https://apis.mapmyindia.com/advancedmaps/v1/l9gtdjyqz4hy2plrxxmkrkvz46ztarg7/rev_geocode"
                    querystring = {"lat":a[1],"lng":a[2]}
                    headers = {
                     'cache-control': "no-cache",
                     'postman-token': "e511fc69-0887-9eb7-8865-08b3afd25902"
                         }
                    response = requests.request("POST", url, headers=headers, params=querystring)
                    res=response.text
                    res=ast.literal_eval(res)
                    res=res["results"]
                    res=res[0]
                    res=res["formatted_address"]

                    location_writer.writerow([a[1],a[2],res])


                if key_check[3]=="key_5":

                    a=key_check


                    url = "https://apis.mapmyindia.com/advancedmaps/v1/hxjlievzoxm8pdqr2vt27fb28tm553ox/rev_geocode"
                    querystring = {"lat":a[1],"lng":a[2]}
                    headers = {
                     'cache-control': "no-cache",
                     'postman-token': "e511fc69-0887-9eb7-8865-08b3afd25902"
                         }
                    response = requests.request("POST", url, headers=headers, params=querystring)
                    res=response.text
                    res=ast.literal_eval(res)
                    res=res["results"]
                    res=res[0]
                    res=res["formatted_address"]

                    location_writer.writerow([a[1],a[2],res])


                if key_check[3]=="key_6":

                    a=key_check


                    url = "https://apis.mapmyindia.com/advancedmaps/v1/lixj3orrkt79psvne2wbm5bymq4j8nu5/rev_geocode"
                    querystring = {"lat":a[1],"lng":a[2]}
                    headers = {
                     'cache-control': "no-cache",
                     'postman-token': "e511fc69-0887-9eb7-8865-08b3afd25902"
                         }
                    response = requests.request("POST", url, headers=headers, params=querystring)
                    res=response.text
                    res=ast.literal_eval(res)
                    res=res["results"]
                    res=res[0]
                    res=res["formatted_address"]

                    location_writer.writerow([a[1],a[2],res])


                if key_check[3]=="key_7":

                    a=key_check


                    url = "https://apis.mapmyindia.com/advancedmaps/v1/wjby24gltm99nrm3eq8ohgzxzjeafwmo/rev_geocode"
                    querystring = {"lat":a[1],"lng":a[2]}
                    headers = {
                     'cache-control': "no-cache",
                     'postman-token': "e511fc69-0887-9eb7-8865-08b3afd25902"
                         }
                    response = requests.request("POST", url, headers=headers, params=querystring)
                    res=response.text
                    res=ast.literal_eval(res)
                    res=res["results"]
                    res=res[0]
                    res=res["formatted_address"]

                    location_writer.writerow([a[1],a[2],res])


                if key_check[3]=="key_8":

                    a=key_check


                    url = "https://apis.mapmyindia.com/advancedmaps/v1/zpuh5cx385m29b1mlgrxwrg3w7n6d1vo/rev_geocode"
                    querystring = {"lat":a[1],"lng":a[2]}
                    headers = {
                     'cache-control': "no-cache",
                     'postman-token': "e511fc69-0887-9eb7-8865-08b3afd25902"
                         }
                    response = requests.request("POST", url, headers=headers, params=querystring)
                    res=response.text
                    res=ast.literal_eval(res)
                    res=res["results"]
                    res=res[0]
                    res=res["formatted_address"]

                    location_writer.writerow([a[1],a[2],res])

                if key_check[3]=="key_9":

                    a=key_check


                    url = "https://apis.mapmyindia.com/advancedmaps/v1/i1wsduwd81xnoi6o4awmjdvnn9cq8pop/rev_geocode"
                    querystring = {"lat":a[1],"lng":a[2]}
                    headers = {
                     'cache-control': "no-cache",
                     'postman-token': "e511fc69-0887-9eb7-8865-08b3afd25902"
                         }
                    response = requests.request("POST", url, headers=headers, params=querystring)
                    res=response.text
                    res=ast.literal_eval(res)
                    res=res["results"]
                    res=res[0]
                    res=res["formatted_address"]

                    location_writer.writerow([a[1],a[2],res])

        cur.execute("""DROP TABLE coordinates_table;""")
        database.close()
        response = "attachment; filename=location_file.csv"
        return response
if __name__ == "__main__":
    app.run(debug=True)
2019-05-31 11:52:13,767: Exception on /upload_confirm [POST]
Traceback (most recent call last):
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 597, in urlopen
    self._prepare_proxy(conn)
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 807, in _prepare_proxy
    conn.connect()
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/urllib3/connection.py", line 324, in connect
    self._tunnel()
  File "/usr/lib/python3.6/http/client.py", line 919, in _tunnel
    message.strip()))
OSError: Tunnel connection failed: 403 Forbidden
**NO MATCH**
During handling of the above exception, another exception occurred:
**NO MATCH**
Traceback (most recent call last):
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 641, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/urllib3/util/retry.py", line 399, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='apis.mapmyindia.com', port=443): Max retries exceeded with url: /advancedmaps/v1/kgpxta9p6y6zjdxnxh6qcwnke19bx8bt/rev_geocode?lat=23.1267128&lng=70.02695465 (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden',)))
**NO MATCH**
During handling of the above exception, another exception occurred:
**NO MATCH**
Traceback (most recent call last):
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/flask/app.py", line 2311, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/flask/app.py", line 1834, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/flask/app.py", line 1737, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/flask/_compat.py", line 36, in reraise
    raise value
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/flask/app.py", line 1832, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/flask/app.py", line 1818, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/jaypaliwal/test_directory/task1webapp.py", line 176, in upload_confirmation
    response = requests.request("POST", url, headers=headers, params=querystring)
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/home/jaypaliwal/.virtualenvs/testenv/lib/python3.6/site-packages/requests/adapters.py", line 510, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='apis.mapmyindia.com', port=443): Max retries exceeded with url: /advancedmaps/v1/kgpxta9p6y6zjdxnxh6qcwnke19bx8bt/rev_geocode?lat=23.1267128&lng=70.02695465 (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden',)))

0 个答案:

没有答案
相关问题