-
Notifications
You must be signed in to change notification settings - Fork 215
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
update_contents_with_stream results in a CORS error in an environment that requires CORS Domains settings. #856
Comments
Hi @tanaga9, This problem certainly looks strange because you can access some endpoints, but CORS blocks file transfers. I would need few more things from you to investigate it further. I had some problems reproducing this issue with the steps provided. Could you provide a small reproducible sample with the BoxSDK code, preferably as a Jupyter notebook/cell, that can be run from a browser? Could also post the entire stack trace of the error you're getting (I think the error itself is missing in the stack trace you posted)? Have you tried with other Python distributions than Pyodide? Or try to reproduce this problem in different environment than Jupyter? Does the same problem occur? Any additional information would help. Also please make sure that CORS is configured correctly on both Box and your app. |
@mwwoda To begin with, CORS errors only occur in very limited execution environments. Conditions for CORS errors in boxsdk
The steps to reproduce the issue are as follows In an environment where you can use Pyodide, such as jupyterlite.
*1: If the CORS domain settings are not correct, The following errors will occur. (This is not a issue)
*2: However, the CORS error for this case is as follows.
it will succeed if you use requests.
I have something I want to try. I want to change the URL of api_config, send a request to my API server, and check how the contents of the header and body are different from others. However, I couldn't figure out how to change the settings. |
Hi @tanaga9, Did you add your domain to the CORS domain in dev portal as follow: Remember to include protocol, domain, port and without slash at the end of url. Best, |
sure. By the way, I am using the jupyterlab_box_drive demonstration page.
|
Hi @tanaga9 I tried the same command with Jupyter Notebook (not jupyterlite) and it's working well from my side. I will let you know if I have any updates. Best, |
Please send us the full exception stack trace, it can help to identify the issue much easier. |
full exception stack trace is here
To begin with, CORS errors only occur in very limited execution environments.
In this context, "Web browser-based Python" does not simply mean that the UI is a web page. If you use JupyterLab, the kernel is actually on the server side, so CORS errors will never occur. As a boxsdk, it is also important for us to decide whether or not to support those environments. |
There are two main types of Python implementations that run on a web browser:
Those that have a kernel running on the server sideIn this type of implementation, Python code is not executed directly in the web browser, but is rendered from a kernel running on the server side. This means that CORS errors and other problems are not possible. Some examples of this type of implementation include:
Those that run Python code directly in the web browserIn this type of implementation, Python code is executed directly in the web browser. This means that CORS errors and other problems are possible. Some examples of this type of implementation include:
|
Thanks for your log @tanaga9, I will check it. By the time, you can also take a look at box/box-python-sdk-gen (still in beta) to check if it's working. |
Thanks @congminh1254 Similarly, box_sdk_gen succeeded with other APIs, but file writes resulted in a CORS Error. traceback
It is possible that this is a problem with pyodide_http. |
I think it could be this issue koenvo/pyodide-http#38 Here is the request body I captured from the Box SDK when pyodide patching all requests:
|
I thought about that too, but at least I was able to successfully upload files using the following method. There may be some complex conditions that need to be met. I'll also ask on koenvo/pyodide-http#38.
|
Hi @tanaga9 As you can see from my comment above, the body send by the SDK is wrapped in So I think this is not an issue with the SDK, but of the pyodide-http library as it still in beta version. I will close this issue for now, if you have any other update or issue, feel free to open it again. Best, |
Description of the Issue
update_contents_with_stream
resulted in a CORS error.client.file(id).update_contents_with_stream(io.BytesIO(content))
requests.post(f'https://upload.box.com/api/2.0/files/content', headers={'Authorization': f'Bearer {jlboxd.oauth.access_token}'}, data={"id": id}, files={'uploadFile': (name, content)})
Part of traceback
Steps to Reproduce
How to use boxsdk in Pyodide (JupyterLite)
Expected Behavior
Error Message, Including Stack Trace
Screenshots
Versions Used
Python SDK: 3.9.2
Python: 3.11.2 (Pyodide)
The text was updated successfully, but these errors were encountered: