Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XMLHttpRequest fails when called more than once #475

Open
odrail opened this issue Mar 11, 2025 · 0 comments
Open

XMLHttpRequest fails when called more than once #475

odrail opened this issue Mar 11, 2025 · 0 comments

Comments

@odrail
Copy link

odrail commented Mar 11, 2025

Issue type

Bug

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

Windows 11

Python version (python --version)

3.12

PythonMonkey version (pip show pythonmonkey)

1.1.0

Bug Description

The first time I call the clientHttp function, it works fine, but when I call it more than once, I get the following error:

  error: NetworkError: Error: Python AttributeError: 'NoneType' object has no attribute 'connect'
    DOMException@C:/Users/emanu/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0/LocalCache/local-packages/Python312/site-packages/pythonmonkey/node_modules/core-js/modules/web.dom-exception.constructor.js:64:17
    #handleErrors@C:/Users/emanu/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0/LocalCache/local-packages/Python312/site-packages/pythonmonkey/builtin_modules/XMLHttpRequest.js:452:48
    C_Users_emanu_AppData_Local_Packages_PythonSoftwareFoundation_Python_3_12_qbz5n2kfra8p0_LocalCache_local_packages_Python312_site_packages_pythonmonkey_builtin_modules_XMLHttpRequest_js/#sendAsync/<@C:/Users/emanu/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0/LocalCache/local-packages/Python312/site-packages/pythonmonkey/builtin_modules/XMLHttpRequest.js:429:38,
function clientHttp(url, options = {}) {
    return new Promise((resolve, reject) => {
        const { method = 'GET' } = options
        const xhr = new XMLHttpRequest()
        xhr.open(method, url, true)

        setHeaders(options.headers, xhr)

        const token = read('token.txt')
        setAuthorization(xhr, token)

        xhr.onerror = (e) => {
            console.log('xhr error:', e)
            reject(xhr.statusText)
        }
        
        xhr.onload = () => {
            if (xhr.status >= 200 && xhr.status < 300) {
                return resolve(parseBody(xhr))
            }
            return reject(parseBody(xhr))
        };

        xhr.send(options.body)
    })
}

Standalone code to reproduce the issue

Relevant log output or backtrace

Additional info if applicable

What branch of PythonMonkey were you developing on? (If applicable)

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

1 participant