简体   繁体   English

server.py 无法启动,路径中的 unicode 字符有问题

[英]server.py wont start, problem with unicode character in path

Okay so I'm trying to run a server using python.好的,所以我正在尝试使用 python 运行服务器。 When I try to start the server though I get this:当我尝试启动服务器时,虽然我得到了这个:

D:\Users\DearJohn28\Downloads\prgm>python3 server.py
INFO:engineio.server:Server initialized for threading.
Traceback (most recent call last):
  File "server.py", line 63, in <module>
    app.initialize()
  File "D:\Users\DearJohn28\Downloads\prgm\app.py", line 21, in initialize
    settings = initSettings()
  File "D:\Users\DearJohn28\Downloads\prgm\prgm\app\settings.py", line 30, in initSettings
    makedirs(settings['downloadLocation'], exist_ok=True)
  File "D:\Python\Python37\lib\os.py", line 213, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "D:\Python\Python37\lib\os.py", line 213, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "D:\Python\Python37\lib\os.py", line 213, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "D:\Python\Python37\lib\os.py", line 223, in makedirs
    mkdir(name, mode)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '\u202aD:'    

I had it work once before so I don't know what happened.我之前有过一次,所以我不知道发生了什么。 As far as I can tell, when it's making a directory there is a unicode character triggering an OSError.据我所知,在创建目录时,有一个 unicode 字符触发了 OSError。

I would say that I'm not too skilled in python, but I follow direction well.我会说我对python不太熟练,但我很好地遵循了方向。

Here's where makedirs() comes in:这是 makedirs() 的用武之地:

#!/usr/bin/env python3
import json
import os.path as path
from os import makedirs

import prgm.utils.localpaths as localpaths

settings = {}
defaultSettings = {}


def initSettings():
    global settings
    global defaultSettings
    currentFolder = path.abspath(path.dirname(__file__))
    configFolder = localpaths.getConfigFolder()
    makedirs(configFolder, exist_ok=True)
    with open(path.join(currentFolder, 'default.json'), 'r') as d:
        defaultSettings = json.load(d)
        defaultSettings['downloadLocation'] = path.join(localpaths.getHomeFolder(), 'mymedia')
    if not path.isfile(path.join(configFolder, 'config.json')):
        with open(path.join(configFolder, 'config.json'), 'w') as f:
            json.dump(defaultSettings, f, indent=2)
    with open(path.join(configFolder, 'config.json'), 'r') as configFile:
        settings = json.load(configFile)
    settingsCheck()
    if settings['downloadLocation'] == "":
        settings['downloadLocation'] = path.join(localpaths.getHomeFolder(), 'mymedia')
        saveSettings(settings)
    makedirs(settings['downloadLocation'], exist_ok=True)
    return settings


def getSettings():
    global settings
    return settings


def getDefaultSettings():
    global defaultSettings
    return defaultSettings


def saveSettings(newSettings):
    global settings
    settings = newSettings
    with open(path.join(localpaths.getConfigFolder(), 'config.json'), 'w') as configFile:
        json.dump(settings, configFile, indent=2)
    return True


def settingsCheck():
    global settings
    global defaultSettings
    changes = 0
    for x in defaultSettings:
        if not x in settings or type(settings[x]) != type(defaultSettings[x]):
            settings[x] = defaultSettings[x]
            changes += 1
    for x in defaultSettings['tags']:
        if not x in settings['tags'] or type(settings['tags'][x]) != type(defaultSettings['tags'][x]):
            settings['tags'][x] = defaultSettings['tags'][x]
            changes += 1
    if changes > 0:
        saveSettings(settings)

prgm.utils.localpaths prgm.utils.localpaths

#!/usr/bin/env python3
import os.path as path
import sys
from os import getenv

userdata = ""
homedata = path.expanduser("~")

if getenv("APPDATA"):
    userdata = getenv("APPDATA") + path.sep + "mymedia" + path.sep
elif sys.platform.startswith('darwin'):
    userdata = homedata + '/Library/Application Support/mymedia/'
elif getenv("XDG_CONFIG_HOME"):
    userdata = getenv("XDG_CONFIG_HOME") + '/mymedia/';
else:
    userdata = homedata + '/.config/mymedia/';


def getHomeFolder():
    return homedata


def getConfigFolder():
    return userdata

How do I go about fixing this?我该如何解决这个问题?

This call makedirs(settings['downloadLocation'], exist_ok=True) seems to indicate that too much information is sent to makedirs.这个调用makedirs(settings['downloadLocation'], exist_ok=True)似乎表明发送到 makedirs 的信息太多。 You need to extract the 'downloadLocation' from settings in the call by running settings['downloadLocation'] to extract the value from your dictionary.您需要通过运行settings['downloadLocation']从您的字典中提取值,从调用中的settings['downloadLocation']中提取settings['downloadLocation']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Client.py 没有连接到 server.py - Client.py doesnt connect to server.py 如何将数据从server.py发送到特定客户端 - How to send data from server.py to specific client Windows 10 不允许 Python server.py 与 client.py 连接 - Windows 10 not allowing Python server.py to connect with client.py 如何在服务器上同时运行 main.js、cros.js 和 server.py - how to run main.js, cros.js and server.py at the same time on a server flask run 不起作用,但 python server.py 起作用了! 环境变量集 - flask run does not work but python server.py does! Environment vars set 函数cvMemStorageAlloc中请求的python server.py错误大小为负数或太大 - python server.py error requested size is negative or too big in function cvMemStorageAlloc 如何从我的本地计算机(client.py)发送一个简单的 UDP 消息到远程服务器 pythonanywhere(server.py) - How to send a simple UDP message from my local computer(client.py) to a remote server pythonanywhere(server.py) Django项目路径中的Unicode字符 - Unicode character in Django project path 如果通过 client.html 将数据存储在 server.py 中,它说我成功了,但是当我尝试检索它时,它说 404 not found - If store data in server.py through client.html it says that I did it successfully, but when I try to retrieve it, it says 404 not found Python-py.path.new Unicode错误 - Python - py.path.new unicode error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM