Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
terryz
3 years agoExplorer | Level 3
Error 400 using download link from embedded code
I have an embedded piece of code that once upon a time worked before TLS v1 was deprecated. Note the URL download link in the subject line above was modified to protect the file. The unmodified link works fine with Chrome and Edge as the client. I have been trying to modify the code in my embedded application to use TLS v1.2 to make it work again. Below is the code snippet that I am trying to modify. I am guessing my header {} settings are incorrect. Below the code is the html response I get back from Dropbox - basically error 400. Do I need to create my own agent to do this or did I not put in the correct header {} information? I am using the typical Edge and Chrome header for 'Agent'...
Code:
local https = require("ssl.https")
local ltn12 = require("ltn12")
local options = {}
local fileMode = isbinary and "wb" or "w"
f = io.open(fulllocalpath, fileMode)
if not f then
resultstr = "Failed to open local file for writing:" .. fulllocalpath .."\r"
return false, nil, nil, resultstr
end
options = {
url = rawname,
sink = ltn12.sink.file(f),
protocol = "tlsv1_2",
headers = { --IS THERE SOMETHING WRONG HERE???
["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36",
["Accept"] = "*/*",
["Accept-Encoding"] = "gzip, deflate, br",
["Connection"] = "keep-alive"
}
}
Here is the html response back from Dropbox:
<.DOCTYPE html> <html> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Dropbox - 400</title> <link href="https://cfl.dropboxstatic.com/static/metaserver/static/css/error.css" rel="stylesheet" type="text/css"/> <link rel="shortcut icon" href="https://cfl.dropboxstatic.com/static/images/favicon.ico"/> </head> <body> <div class="figure"> <img src="https://assets.dropbox.com/www/en-us/illustrations/spot/target-miss.svg" alt="Error: 400"/> </div> <div id="errorbox"> <h1>Error (400)</h1>Something went wrong. Don't worry, your files are still safe and the Dropbox team has been notified. Check out our <a href="https://status.dropbox.com">Status Page</a> to see if there is a known incident, our <a href="https://www.dropbox.com/help">Help Center</a> and <a href="https://forums.dropbox.com">forums</a> for help, or head back to <a href="https://www.dropbox.com/home">home</a>. </div> </body> </html>
32 Replies
Replies have been turned off for this discussion
- Greg-DB3 years ago
Dropbox Community Moderator
terryz I see you're setting the "url" to "https://www.dropbox.com" now, instead of your shared link, and so you're retrieving the HTML of the Dropbox home page.
I also see that you're trying to set a "Path" header to "/s/y5jlwu5nfr3s8xe/FAULTMSG.CSV?dl=1", however that should be part of the HTTP start line, not a header.
The network client is generally expected to handle these details for you automatically; that is, you should be able to just supply the URL and it would handle the host and path details for you automatically.
If you set the "url" to the full shared link with this code, and don't set a "Path" header, does it get the expected file content? If the home page works but the shared link doesn't, it's possible your client just doesn't support redirects.
- terryz3 years agoExplorer | Level 3
HI:
I am still stuck on this problem. I used this download link: https://uccef767ef880d6a3502e4b4c6d8.dl.dropboxusercontent.com/cd/0/get/B-vL_FjzfpbTyi_k94SzGhqqvG9QHT1CUYLd3C17VUfLzkEMfNwV5fvXZoYO1td1WZhJfBs0-chFbS12zcOEoEDCyh-NdZzUYp_Z-gMcL3lK5ebsNWJ3PozlzQLOW8oVaafVrlraw-iygnZkzZC3tinXOppvcp-L4E14ND29ah7CTtRdCaRMlBDjD6suA2naIsM/file?dl=1#
And I get the dropbox Error 400 "Something went wrong" page.
I am using this for the https request:
resp, resultcode, respheaders, respstatus = https.request{url = rawname,sink = ltn12.sink.file(io.open(fulllocalpath, "wb")),protocol = "tlsv1_2",verify = "none",options = "all",headers = {["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",["Accept"] = "*/*",["Connection"] = "keep-alive",}} - Greg-DB3 years ago
Dropbox Community Moderator
terryz That particular link has expired now (and so fails with a 410), but I notice it does end with a "#". That would normally be fine, as network clients are supposed to automatically remove that before issuing a network request (curl does, for example), but it's possible that your network client is not doing so, and so corrupting the request. Can you try it with a new one of those links but manually remove the "#" first?
- terryz3 years agoExplorer | Level 3
That gave me a 404 error..
- Greg-DB3 years ago
Dropbox Community Moderator
terryz Can you double check that you only removed the "#" and did not otherwise modify the link? I can't reproduce that 404 with curl.
Also, note that these /cd/0/get/ links that result from the redirects can each only be used once, so you'd need to receive the link and remove the trailing "#" before you issue a request to it.
- terryz3 years agoExplorer | Level 3
OK, progress!
It works now using the 1 time download link with the '#' removed.
However, a 1 time link is not practical in our application...
When I go back to the 'standard link' [https://www.dropbox.com/s/y5jlwu5nfr3s8xe/FAULTMSG.CSV?dl=0], Iam still getting a 400 error code.
What goes on under the hood of dropbox that enables a web browser like Edge or chrome to use the 'standard' link continuously?
- Greg-DB3 years ago
Dropbox Community Moderator
terryz Other clients/browsers support the ability to correctly handle redirects as well as withhold the "fragment" portion of the URL (the "#" part) when sending requests. These enable them to go from the original URL through to the final URL where the file data is returned. Based on what I've seen in this thread it appears the network client you're using does not correctly handle one or both of those behaviors.
By the way, I notice you have "dl=0" in your latest message, but that should be "dl=1" like you had in earlier messages. I expect you've already that had correct in your code previously, but it's worth checking since that parameter is necessary for this use case.
- terryz3 years agoExplorer | Level 3
Correct, it was dl=1.
What I am getting back is the following header to the URL https://www.dropbox.com/s/y5jlwu5nfr3s8xe/FAULTMSG.CSV?dl=1 is the following;
Why am I getting back a response of 400 with a redirect link?
resultcode [400].
headers: x-dropbox-response-origin:local
headers: content-type:text/html
headers: location:https://uc16524db6bb71d5534145f43f41.dl.dropboxusercontent.com/cd/0/get/B-y6cEeORVMMdIB4gjagTUX1yqaznPpvtxEAaIMWaMgYvlPnz9gApnmN5Uh_Ol6TeuDQYDw5RVdUfpnhcrRyzWvx6e9jtmqpHChrnTp3lXMjGweuZPtT1dHIeSpCSlrGswTQc-fr6mhCFf5c9QNCUxEam3dIxAqAJvp30KVhoaeum4dSAVdzecaqBBgvWpzQOjQ/file?dl=1#
headers: vary:Accept-Encoding
headers: content-length:1005
headers: connection:close
headers: date:Tue, 27 Jun 2023 20:03:08 GMT
headers: server:envoy - Greg-DB3 years ago
Dropbox Community Moderator
A 400 like that indicates that there was something incorrect about the HTTP request issued by the client. (When following the redirects from the original link, there would be multiple requests made.)
For example, as we found it seems the client is incorrectly sending the fragment ("#") on that particular link.
Ultimately, as this does not reproduce with other clients, it appears this is an issue with the specific network client you're using. That client is not made by Dropbox and the behavior of that client is out of our control so we can't provide support for it in particular.
- terryz3 years agoExplorer | Level 3
Hi - I do take out the '#' on the redirect link.
It is now working with the 'standard' link, however I am still getting a 400 error when I use the standard link https://www.dropbox.com/s/gxxxxxxxxblablahfile.TXT?dl=1. This returns error 400.
So I modified the code to ignore this error 400 and look for the redirect URL anyway, which is provided, despite getting the 400 from dropbox.com.
The code then strips off the trailing '#' character, and reissues new http request with the redirect link. The file is downloaded successfully, and the return code is now 200 - indicating success, which it is!
So...why am I getting a 400 error on the first http request with the standard link, but I still get a redirect URL to the file anyway, and then making the exact same http request except modifying the url to the redirect link, then get the file downloaded and code 200?
Here is my header setup - what is wrong with it causing the initial error 400?
resp, resultcode, respheaders, respstatus = https.request{
url = rawname,
sink = ltn12.sink.file(io.open(fulllocalpath, "wb")),
protocol = "tlsv1_2",
verify = "none",
options = "all",
--method = "GET",
headers = {
["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
["Accept"] = "*/*",
["Connection"] = "keep-alive"
}
}
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!