[英]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.