Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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 3.x 如何修复从url读取文件时瓶子路由保持加载的错误?_Python 3.x_Bottle - Fatal编程技术网

Python 3.x 如何修复从url读取文件时瓶子路由保持加载的错误?

Python 3.x 如何修复从url读取文件时瓶子路由保持加载的错误?,python-3.x,bottle,Python 3.x,Bottle,我需要保存url“”发送的文件。 当我用python文件运行程序时,代码是有效的。但是,当通过函数浏览器使用相同的代码路由函数时,陷入加载,服务器崩溃。你能帮我解决这个问题吗 import urllib from urllib.request import urlopen from bottle import run, route, template, request, get, post from urllib.parse import urlparse @get("/getjourney

我需要保存url“”发送的文件。 当我用python文件运行程序时,代码是有效的。但是,当通过函数浏览器使用相同的代码路由函数时,陷入加载,服务器崩溃。你能帮我解决这个问题吗

import urllib
from urllib.request import urlopen
from bottle import run, route, template, request, get, post
from urllib.parse import urlparse


@get("/getjourney")
def getjourney():
    response = "Journey1"
    f = open('XML files/' + response + '.xml').read()
    return "f"


@route('/savejourney')
def savejourney():
    url = 'http://127.0.0.1:8080/getjourney'
    response = urllib.request.urlopen(url)
    xml1 = response.read()
    print(xml1)
    xml = open('../XML files/new.xml', "w")
    xml.write(str(xml1))

我希望将url“”返回的文件保存在文件夹中。

您的浏览器尝试显示/呈现此xml内容。这样做可能会导致一些错误。试试这个,看看它是否适合你:

import html
@get("/getjourney")
def getjourney():
    response = "Journey1"
    f = open('XML files/' + response + '.xml').read()
    return html.escape(f)

欢迎您需要详细说明“服务器崩溃”,以便我们可以帮助您。它是如何崩溃的?包括崩溃转储的重要部分(例如异常和堆栈跟踪)。