好的,所以我正在尝试使用 python 运行服务器。当我尝试启动服务器时,虽然我得到了这个:
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:'
我之前有过一次,所以我不知道发生了什么。据我所知,当它创建一个目录时,有一个触发 OSError 的 unicode 字符。
我会说我对python不太熟练,但我很好地遵循了方向。
这里是 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
#!/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
我该如何解决这个问题?