0

So when ever im trying to debug any Python script on VS code an that script has a print or input statement, it crashes an throws me an "AttributeError" that says 'NoneType' object has no attribute 'write', any ideas why this happens? i cant find any information on Google about it here is a screenshot in the error:Link to the screenshot and also here is my configuration file:

{
// Use IntelliSense para saber los atributos posibles.
// Mantenga el puntero para ver las descripciones de los existentes atributos 
// Para más información, visite: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "Python: Current File (Integrated Terminal)",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "program": "${file}",
        "console": "integratedTerminal"
    },
    {
        "name": "Python: Attach",
        "type": "python",
        "request": "attach",
        "port": 5678,
        "host": "localhost"
    },
    {
        "name": "Python: Django",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/manage.py",
        "console": "integratedTerminal",
        "args": [
            "runserver",
            "--noreload",
            "--nothreading"
        ],
        "django": true
    },
    {
        "name": "Python: Flask",
        "type": "python",
        "request": "launch",
        "module": "flask",
        "env": {
            "FLASK_APP": "app.py"
        },
        "args": [
            "run",
            "--no-debugger",
            "--no-reload"
        ],
        "jinja": true
    },
    {
        "name": "Python: Current File (External Terminal)",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "externalTerminal"
    }
]

}

2 Answers 2

1

VSCODE working fine for me

a) Install VSCODE or upgrade to version 1.28.1 b) REFRESH Python Extension

If you face any issue like timeout etc read https://github.com/Microsoft/vscode-python/issues/2410 very carefully

Edit settings.json of python extension a) Disable Terminal: Activate Environment Activate Python Environment in Terminal created using the Extension.

b) enable Terminal: Execute In File Dir When executing a file in the terminal, whether to use execute in the file's directory, instead of the current open folder.

c) Remove pythonW and put python in Python Path Path to Python, you can use a custom version of Python by modifying this setting to include the full path.

Everything above from https://github.com/Microsoft/vscode-python/issues/2410

Though a happy ending I can foresee a future of unstable releases for a wonderful VSCODE and even better Python Extension

Sign up to request clarification or add additional context in comments.

Comments

0

An attribute error usually means that whatever object your working with is actually none. This can happen because something happened upstream or downstream of your call.

In the case of your single print statement, the only thing I can think of is perhaps it has something do so with double quotes.. It doesn't really make sense that double quotes would cause this but who knows.

what happens when you try

print('I will crash!!!')

If that still fails then I would say that perhaps vs is trying to write to a file, configuration, log, console or something else and is running into permission issues.

EDIT After looking closesr at your configuration files, I see you have two that start with

"name": "Python: Current File ....

So I rewrote your config file, it still includes the specific files that were named, and their configs, but I eliminated one of the current file entries and made it basic.

{
// Use IntelliSense para saber los atributos posibles.
// Mantenga el puntero para ver las descripciones de los existentes atributos 
// Para más información, visite: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "Python: Current File (External Terminal)",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "externalTerminal"
    },
    {
        "name": "Python: Attach",
        "type": "python",
        "request": "attach",
        "port": 5678,
        "host": "localhost"
    },
    {
        "name": "Python: Django",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/manage.py",
        "console": "integratedTerminal",
        "args": [
            "runserver",
            "--noreload",
            "--nothreading"
        ],
        "django": true
    },
    {
        "name": "Python: Flask",
        "type": "python",
        "request": "launch",
        "module": "flask",
        "env": {
            "FLASK_APP": "app.py"
        },
        "args": [
            "run",
            "--no-debugger",
            "--no-reload"
        ],
        "jinja": true
    }
]
}

I have it set up to use the external console (standard windows cmd). If you want to use the vs console replace

{
    "name": "Python: Current File (External Terminal)",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "externalTerminal"
},

with

{
    "name": "Python: Current File (Integrated Terminal)",
    "type": "python",
    "request": "launch",
    "stopOnEntry": true,
    "program": "${file}",
    "console": "integratedTerminal"
},

Do NOT forget to save a copy of your old config file first. That way if VS freaks out from manually changing this file you can always revert back.

I am looking for the possibility that VS can't decide which terminal to output too, but at the same time you only get this while debugging so....

Now I did see a flag in the config for no debug but it was for a flask app.

5 Comments

it still crashes, any ideas of how could i check if its trying to write to a file? if instead of a print i put, for example, input("i will crash!"), then the AttributeError says "Nonetype" object has no attribute "readline", plus, this only happens when i debug it
does this happen with every file or just this one file? If you were to create a new from scratch file with a lone print statement what happens.
Also your screen shot shows some data in the local variables under exception can you post this data?
Very Easy to reproduce In debug console type print("jnc") print("jnc") AttributeError("'NoneType' object has no attribute 'write'",) It happens on my Windows 10 latest updated VSCODE Version: 1.28.0 (system setup) Commit: 431ef9da3cf88a7e164f9d33bf62695e07c6c2a9 Date: 2018-10-05T14:58:53.203Z Electron: 2.0.9 Chrome: 61.0.3163.100 Node.js: 8.9.3 V8: 6.1.534.41 Architecture: x64
Raised issue github.com/Microsoft/vscode/issues/60436 This happens in 1 PC but not another

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.