Problem in python

when I run this it gives me traceback (most recent call last):

file "C:\new folder\", line 90, in <module> main()
file "C:\new folder\", line 71, in main create_folders()
file "C:\new folder\", line 66, in create_folders os.makedirs(folder)
file "<frozen os>", line 225, in makedirs
PermissionError: [WinError 5] access denied "valid_url"

Im french :sweat_smile:

Welcome to the Python Discourse! As a reminder, please don’t post screenshots of your code. Instead, post code and complete tracebacks as code, inside a code block like this:


You can copy-paste the above, or use the </> button in the editing toolbar. I fixed the formatting around your traceback in your post above, so you can also use that as an example.

Anyway, as the error message states:

For one reason or another, the user account you’re running your script under does not have permission to create a new folder in the indicated directory. This is entirely controlled by your operating system rather than Python, so you’ll need to check your operating system permissions on that. Instead of running it in the root of your drive, you might want to run it in your user home directory instead (C:/Users/<username> on Windows), where you should have full permissions. Or, if you do create a directory somewhere else, check the permissions on the parent directory to make sure your user has full read write permissions on anything created therein.

On a side note, you can greatly simplify your code by taking advantage of options already built in to the functions you’re using. For example, you have this code:


You can use the exist_ok and mode arguments to os.makedirs to replace all of the above manual code with just:

def create_folders(folders=('valid_urls', 'invalid_urls')):
    for folder in folders:
        os.makedirs(folder, mode=0o777, exist_ok=True)

You might want to consider use of the pathlib standard library module instead of the older os.path, as many operations are simpler, cleaner and easier to use.

1 Like

3 posts on a completely different issue were split to a new topic: [Split] TypeError: Updater.init() got an unexpected keyword argument ‘use_context’

As a sidenote, this is one good reason why you should avoid giving your post a generic title like “Problem in Python” (that could apply to nearly every one of the posts in Python Help :slight_smile: ) and give it an actual useful, helpful title describing the problem instead. (I used to do that for users at least on the most egregious examples, but I’ve refrained from doing so at all ever since it upset another user here.)