Alright, I'm creating a Python project of mine using my two favorite modules. Flask and discord. Now thus to say, I'm not the best, but I'm encountering a new error when trying to create a new file when directory is empty of said name. Here's the error I'm getting:
2.168.0.26 - - [18/Jun/2021 21:30:42] "GET / HTTP/1.1" 404 -
Trying to open Mewniverse's folder
File not found error raised
File not accessible. creating new.
[2021-06-18 21:30:42,559] ERROR in app: Exception on /favicon.ico [GET]
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/flask/app.py", line 2070, in wsgi_app
response = self.full_dispatch_request()
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/flask/app.py", line 1515, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/flask/app.py", line 1513, in full_dispatch_request
rv = self.dispatch_request()
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.8/site-packages/flask/app.py", line 1499, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "<string>", line 53, in hello_world
OSError: [Errno 30] Read-only file system: '/Mewniverse'
192.168.0.26 - - [18/Jun/2021 21:30:42] "GET /favicon.ico HTTP/1.1" 500 -
Now here's my code(ignoring indentation and unfinished parts as it is heavily unfinished):
def hello_world(ID):
print(f"Trying to open {ctx.author.name}'s folder")
directory = f'/{ctx.author.name}'
parent_dir = 'userFiles/templates'
path = os.path.join(parent_dir, directory)
if os.path.isfile(path):
print ("File exist")
else:
print(f'File not found error raised')
print("File not accessible. creating new.")
f = open(path, "w")
f.write("Now the file has more content!")
f.close()
print("Directory created and written in")
return render_template(f'{ctx.author.name}.html')
app.run(host='0.0.0.0', port=8080)
await ctx.message.channel.send(f'Here you go {ctx.author.name}! Your site will be here: http://192.168.0.26:8080/{ctx.author.name}')
I've been stuck here for a few hours, so I'm hoping someone could help find a solution quickly. Thanks if possible.