Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
terryz
2 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 lin...
terryz
2 years agoExplorer | Level 3
HI - Some progress!
This is the current header configuration.
-- Set the options for the HTTPS request
local options = {
protocol = "tlsv1_2",
sink = ltn12.sink.file(f),
--method = "GET", -- Add the method field to specify the HTTP method
verify = "none",
options = "all",
headers = {
["Path"] = "/s/y5jlwu5nfr3s8xe/FAULTMSG.CSV?dl=1",
["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"] = "*/*",
["Accept-Language"] = "en-US,en;q=0.9",
}
}
I am receiving Http Request response 200.
HOWEVER, the data that is coming in is an HTML doc with a bunch of script, not the actual file - how to I get the actual file?
This is what is coming in now:
<!DOCTYPE html><html class="maestro maestro--responsive global-header" lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"><head><script nonce="ZRxUjr5/dF9DyBZrrJ6q">
window._goch_ = {};
window.addEventListener('click', function(event) {
'use strict';
for (var elm = event.target; elm; elm = elm.parentElement) {
if (elm.id &&
window._goch_.hasOwnProperty(elm.id) &&
window._goch_[elm.id].call(elm, event) === false) {
event.preventDefault();
}
}
}, true);
window._csp_external_script_nonce = "7kuyd45qCXX16APN0jQ5"</script><link href="https://cfl.dropboxstatic.com" rel="preconnect" /><link href="https://cfl.dropboxstatic.com/static/metaserver/static/images/favicon-vfl8lUR9B.ico" rel="shortcut icon" /><title>Dropbox.com</title><meta content="all" name="robots" /><link href="https://www.dropbox.com/" rel="canonical" /><link href="https://www.dropbox.com/da_DK/" hreflang="da-dk" rel="alternate" /><link href="https://www.dropbox.com/de/" hreflang="de-de" rel="alternate" /><link href="https://www.dropbox.com/" hreflang="en" rel="alternate" /><link href="https://www.dropbox.com/en_GB/" hreflang="en-gb" rel="alternate" /><link href="https://www.dropbox.com/es/" hreflang="es" rel="alternate" /><link href="https://www.dropbox.com/es_ES/" hreflang="es-es" rel="alternate" /><link href="https://www.dropbox.com/fr/" hreflang="fr-fr" rel="alternate" /><link href="https://www.dropbox.com/id/" hreflang="id-id" rel="alternate" /><link href="https://www.dropbox.com/it/" hreflang="it-it" rel="alternate" /><link href="https://www.dropbox.com/ja/" hreflang="ja-jp" rel="alternate" /><link href="https://www.dropbox.com/ko/" hreflang="ko-kr" rel="alternate" /><link href="https://www.dropbox.com/ms/" hreflang="ms-my" rel="alternate" /><link href="https://www.dropbox.com/nb_NO/" hreflang="nb-no" rel="alternate" /><link href="https://www.dropbox.com/nl_NL/" hreflang="nl-nl" rel="alternate" /><link href="https://www.dropbox.com/pl/" hreflang="pl-pl" rel="alternate" /><link href="https://www.dropbox.com/pt_BR/" hreflang="pt-br" rel="alternate" /><link href="https://www.dropbox.com/ru/" hreflang="ru-ru" rel="alternate" /><link href="https://www.dropbox.com/sv_SE/" hreflang="sv-se" rel="alternate" /><link href="https://www.dropbox.com/th_TH/" hreflang="th-th" rel="alternate" /><link href="https://www.dropbox.com/uk_UA/" hreflang="uk-ua" rel="alternate" /><link href="https://www.dropbox.com/zh_CN/" hreflang="zh-cn" rel="alternate" /><link href="https://www.dropbox.com/zh_TW/" hreflang="zh-tw" rel="alternate" /><meta content="origin-when-cross-origin" name="referrer" /><meta content="width=device-width, initial-scale=1" name="viewport" /><meta content="app-id=327630330" name="apple-itunes-app" /><script type="text/javascript" nonce="ZRxUjr5/dF9DyBZrrJ6q">if (window.performance && window.performance.mark) { window.performance.mark("requirejs_start"); }</script> <link crossorigin="anonymous" href="https://cfl.dropboxstatic.com/static/metaserver/static/js/alameda_bundle/alameda_bundle_chrome_en-vflNKspnr.js" as="script" nonce="7kuyd45qCXX16APN0jQ5" rel="preload" type="text/javascript" /> <script type="text/javascript" nonce="ZRxUjr5/dF9DyBZrrJ6q">
(()=>{"use strict";const e=window;let a;const r=()=>{a=[],e.addRequireLoadCallback=e=>a.push(e),e.configureRequire=function(){const a=arguments;e.addRequireLoadCallback(()=>e.configureRequire.apply(null,a))},e.define=function(){const a=arguments;e.addRequireLoadCallback(()=>e.define.apply(null,a))},e.preLoadFile=(...a)=>{e.addRequireLoadCallback(()=>e.preLoadFile.apply(null,a))}};r(),e._insertRequireShim=r,e.InitRequireJs=r=>{e.requireContexts={},e.performance&&null!=e.performance.now&&(requirejs.onResourceLoad=(a,r,i)=>{const l=e.performance.now(),n=e.requireContexts[a.id];if(n){r.id in n.module_callback_times||(n.module_callback_times[r.id]={});const e=n.module_callback_times[r.id];e.loadTime=l,r.url&&(e.url=r.url),r.id&&(e.name=r.id),r.parentMap&&r.parentMap.url&&(e.parent=r.parentMap.url)}}),e.configureRequire=r,e.addRequireLoadCallback=e=>e(),a.forEach(e=>e())}})();
window.CSP_SCRIPT_NONCE = "ZRxUjr5/dF9DyBZrrJ6q";
</script> <script async="async" crossorigin="anonymous" src="https://cfl.dropboxstatic.com/static/metaserver/static/js/alameda_bundle/alameda_bundle_chrome_en-vflNKspnr.js" type="text/javascript" nonce="7kuyd45qCXX16APN0jQ5"></script> <link crossorigin="anonymous" href="https://cfl.dropboxstatic.com/static/metaserver/static/fonts/dig-fonts/sharp_grotesk_23/SharpGroteskDBCyrBook23-vflX-NIwB.woff2" as="font" rel="preload" type="font/woff2" /><link crossorigin="anonymous" href="https://cfl.dropboxstatic.com/static/metaserver/static/fonts/dig-fonts/sharp_grotesk/SharpGroteskDBCyrBook20-vfl6-4ZSp.woff2" as="font" rel="preload" type="font/woff2" /><link crossorigin="anonymous" href="https://cfl.dropboxstatic.com/static/metaserver/static/fonts/dig-fonts/atlas_grotesk/AtlasGrotesk-Regular-Web-vflk7bxjs.woff2" as="font" rel="preload" type="font/woff2" /> <link href="https://cfl.dropboxstatic.com/static/metaserver/static/css/dig-components/tokens-vflR97xg7.css" rel="stylesheet" /><link href="https://cfl.dropboxstatic.com/static/typescript/component_libraries/dwg-components/src/experimental/components/dwg-toggle-button/index.module.out-vfldjr_iJ.css" rel="stylesheet" /><link href="https://cfl.dropboxstatic.com/static/typescript/component_libraries/dwg-components/src/components/dwg-strikethrough-text/index.module.out-vfl7ItJO0.css" rel="stylesheet" /><link href="https://cfl.dropboxstatic.com/static/metaserver/static/css/warp/skip_to_main_content-vflFXXrjC.css" rel="stylesheet" /><link href="https://cfl.dropboxstatic.com/static/metaserver/static/css/dig-fonts/sharp_grotesk_23.metaserver-vflgQV__K.css" rel="stylesheet" /><link href="https://cfl.dropboxstatic.com/static/typescript/component_libraries/dwg-components/src/index.web-vflHlB-6O.css" rel="stylesheet" /><link href="https://cfl.dropboxstatic.com/static/metaserver/static/css/notify-vfl4oJv2S.css" rel="stylesheet" /><link href="https://cfl.dropboxstatic.com/static/metaserver/static/css/dig-fonts/index.metaserver-vflgFIjQa.css" rel="stylesheet" /><link href="https://cfl.dropboxstatic.com/static/metaserver/static/css/accessibility-vfliGZNRm.css" rel="stylesheet" /><link href="https://cfl.dropboxstatic.com/static/typescript/component_libraries/dwg-components/src/components/dwg-label/index.module.out-vflida7Ix.css" rel="stylesheet" /><link href="https://cfl.dropboxstatic.com/static/metaserver/static/css/google_one_tap-vfl-icCpr.css" rel="stylesheet" /> <style type="text/css">
</style><script type="text/javascript" nonce="ZRxUjr5/dF9DyBZrrJ6q">if (window.performance && window.performance.mark) { window.performance.mark("ensemble_payload_start"); }</script> <script type="text/javascript" nonce="ZRxUjr5/dF9DyBZrrJ6q">window._REPORT_ALL_JS_EXCEPTIONS_ENABLED = true;</script> <script type="text/javascript" nonce="ZRxUjr5/dF9DyBZrrJ6q">(function(){"use strict";const PerfTimer="object"==typeof performance&&"function"==typeof performance.now?performance:Date,FAST_FRAME_THRESHOLD=20,SLOW_FRAME_THRESHOLD=34;class CPUIdleMonitor{constructor(){this.idleCPUTime=0,this.busyCPUTime=0,this.startedTracking=PerfTimer.now(),this.lastFrame=this.startedTracking,this.requestID=requestAnimationFrame((()=>{this.updateCPUTimes()})),console.timeStamp&&console.timeStamp("cpu_idle_tracking_started")}updateCPUTimes(e={forceUpdate:!1,currentCPUSpan:0}){const t=PerfTimer.now(),s=t-this.lastFrame;let r;this.lastFrame=t,r=s>=SLOW_FRAME_THRESHOLD?0:s<=FAST_FRAME_THRESHOLD?1:(SLOW_FRAME_THRESHOLD-s)/(SLOW_FRAME_THRESHOLD-FAST_FRAME_THRESHOLD);let n=s*(1-r);e.forceUpdate&&n<e.currentCPUSpan&&(n=Math.min(s,e.currentCPUSpan)),this.busyCPUTime+=n,this.idleCPUTime+=s-n,e.forceUpdate||(this.requestID=requestAnimationFrame((()=>{this.updateCPUTimes()})))}stop(){null!==this.requestID&&(console.timeStamp&&console.timeStamp("cpu_idle_tracking_stopped"),cancelAnimationFrame(this.requestID),this.requestID=null)}getIdleCPUTime(){return this.idleCPUTime}getCPUTimeSnapshot(e){return void 0!==e&&this.updateCPUTimes({forceUpdate:!0,currentCPUSpan:e}),{idleTime:this.idleCPUTime.toString(),busyTime:this.busyCPUTime.toString()}}getTotalTrackedTime(){return this.idleCPUTime+this.busyCPUTime}getIdlePercentOfTracked(){const e=this.idleCPUTime+this.busyCPUTime;return 0===e?0:this.idleCPUTime/e}getUntrackedTimeSinceTTFB(){if("object"!=typeof performance||"function"!=typeof performance.now||"object"!=typeof performance.timing||"number"!=typeof performance.timing.responseStart||"number"!=typeof performance.timing.navigationStart)return null;const e=performance.timing.responseStart-performance.timing.navigationStart;return this.startedTracking-e}}function reportNonceMismatch(e,t){window.addRequireLoadCallback((()=>{setTimeout((()=>{const s=new Error("Refused to execute script from because window.CSP_SCRIPT_NONCE is defined and the nonce doesn't match.");throw s.excExtra={page_nonce:e,script_tag_nonce:t,err_version:3},s.tags=["csp-nonce-error"],s}),0)}))}const hasPerfNow=!(!window.performance||!window.performance.now);function consoleTimeStamp(e){console.timeStamp&&console.timeStamp(e)}class EnsembleStopwatch{constructor(){this._data={}}getNow(){if(hasPerfNow)return window.performance.now()}markSpan(e,t={}){if(consoleTimeStamp(e),"number"!=typeof t.startTime&&(t.startTime=0),"number"!=typeof t.endTime){const e=this.getNow();if(void 0===e)return;t.endTime=e}t.startTime=Math.round(t.startTime),t.endTime=Math.round(t.endTime),this._data[e]?console.error("stopwatch error: spanName has been used before: "+e):this._data[e]={start:t.startTime,end:t.endTime,annotations:t.annotations||{}}}getData(){const e={};for(const t in this._data)if(this._data.hasOwnProperty(t)){const s=this._data[t];e[t]={end:s.end,start:s.start,annotations:s.annotations}}return e}}class EventTracker{constructor(){this._postEventCallbacks=[],this._eventMarked=!1}callAfterEvent(e){this._eventMarked?e():this._postEventCallbacks.push(e)}_triggerPostEventCallbacks(){for(const e of this._postEventCallbacks)e();this._postEventCallbacks=[]}markEvent(){if(this._eventMarked)throw new Error("event can't be marked twice");this._eventMarked=!0,this._triggerPostEventCallbacks()}}const ScriptTypes=["text/javascript","text/ecmascript","application/javascript","application/ecmascript","",void 0];function insertPagelet(e,t){return e.innerHTML=t,t=>_evaluateScripts(e,t)}function evaluateScript(e,t){const s=document.createElement("div");return s.innerHTML=e,_evaluateScripts(s,t)}function _evaluateScripts(e,t){const s=e.getElementsByTagName("script");for(let e=0;e<s.length;e++){const r=s[e];if(-1===ScriptTypes.indexOf(r.type))continue;const n=r.nonce||r.getAttribute("nonce"),o=window.CSP_SCRIPT_NONCE;if(o===n){if(r.src)throw new Error("Do not add scripts with src in the pagelet html, they should instead be loaded via requirejs or as pagelet dependencies");eval.call(window,r.innerHTML)}else t(o,n)}}const loaderOrder=["loadCssWithCache","CssEntryPoint","css-modules"],sortedLoaders=["css-modules"];function findInsertPosition(e,t,s){if(s[t].length>0){if(sortedLoaders.includes(t)){const r=s[t];for(let t=0;t<r.length;t++){const{elem:s,path:n}=r[t];if(n>e.path)return[s,t]}}return[s[t][s[t].length-1].elem.nextElementSibling,null]}const r=loaderOrder.indexOf(t);for(let e=r-1;e>=0;e--){const t=s[loaderOrder[e]];if(t.length>0)return[t[t.length-1].elem.nextElementSibling,null]}for(let e=r+1;e<loaderOrder.length;e++){const t=s[loaderOrder[e]];if(t.length>0)return[t[0].elem,null]}return[null,null]}function injectCssElement(e,t,s,r,n){e.elem.setAttribute("data-loader",t),e.elem instanceof HTMLStyleElement&&e.elem.setAttribute("path",e.path);let o=null,i=null;n||([o,i]=findInsertPosition(e,t,s)),null===i?s[t].push(e):s[t].splice(i,0,e),o?r.insertBefore(e.elem,o):r.appendChild(e.elem)}function injectCss(e,t,s=document){const r=s.defaultView;r.__injectCssCache||(r.__injectCssCache={loadCssWithCache:[],CssEntryPoint:[],"css-modules":[]});const n=r.__injectCssCache,o=sortedLoaders.includes(t);if(!o&&e.length>1){const[r]=findInsertPosition(e[0],t,n),i=s.createDocumentFragment();for(const s of e)injectCssElement(s,t,n,i,!o);null===r?s.head.appendChild(i):s.head.insertBefore(i,r)}else for(const r of e)injectCssElement(r,t,n,s.head,!1)}const _loadedCSS={},_CSSElements={};function appendLinkTags(e,t,s){const r=[];for(const e of t){const t=_CSSElements[e];if(t)if(_loadedCSS[e])s();else{const r=t.onload,n=t.onerror;t.onload=()=>{s(),r()},t.onerror=()=>{s({resource:e,type:"stylesheet"}),n()}}else{const t=document.createElement("link");t.href=e,t.rel="stylesheet",t.onload=()=>{_loadedCSS[e]=!0,s()},t.onerror=()=>{s({resource:e,type:"stylesheet"})},r.push({elem:t,path:e}),_CSSElements[e]=t}}injectCss(r,"CssEntryPoint",e)}function appendScriptTags(e,t,s){let r;window.hasOwnProperty("_csp_external_script_nonce")&&(r=window._csp_external_script_nonce);for(const n of t){const t=document.createElement("script");t.src=n,t.type="text/javascript",t.async=!0,t.onload=()=>{s()},t.onerror=()=>{s({resource:n,type:"script"})},r&&t.setAttribute("nonce",r),e.appendChild(t)}}class ResourceLoader{constructor(e,t){this.totalResources=0,this.loadedResources=0,this.onLoadCallbacks=[],this.errors=[],e.stylesheets&&(this.totalResources+=e.stylesheets.length),e.scripts&&(this.totalResources+=e.scripts.length),t&&this.onLoadCallbacks.push(t),0!==this.totalResources?this.loadResources(e.stylesheets,e.scripts):setTimeout(this.runCallbacks.bind(this),0)}isDoneLoading(){return this.loadedResources===this.totalResources}addOnLoadCallback(e){if(this.isDoneLoading())throw new Error("ResourceLoader error: added callback after resources have finished loading");this.onLoadCallbacks.push(e)}loadResources(e,t){const s=function(e){this.loadedResources+=1,e&&this.errors.push(e),this.loadedResources===this.totalResources&&this.runCallbacks()}.bind(this);if(e&&appendLinkTags(document,e,s),t){const e=document.createDocumentFragment();appendScriptTags(e,t,s),document.body.appendChild(e)}}runCallbacks(){let e;if(0!==this.errors.length){e={failedStylesheets:[],failedScripts:[]};for(const t of this.errors)"stylesheet"===t.type?e.failedStylesheets.push(t.resource):"script"===t.type&&e.failedScripts.push(t.resource)}for(let t=0;t<this.onLoadCallbacks.length;t++)this.onLoadCallbacks[t](e)}}function doFrameBust(e){if(e.mini_frame_bust){let e=!1;try{e=top.location.hostname===self.location.hostname}catch(e){}if(self!==top&&!e){setTimeout((()=>{window.DB_FRAME_BUST=!0,document.body.innerHTML="<img src='https://cfl.dropboxstatic.com/static/metaserver/static/images/logo.png' id='frame-bust-image'/>",document.getElementById("frame-bust-image").addEventListener("click",(function(e){top.location.href=window.location.href}))}),4);try{top.location.replace(self.location.href)}catch(e){console.error(e)}}}e.frame_bust&&self===top&&(document.body.style.display="")}class TTITracker{constructor(){this._postTTICallbacks=[],this.ttiMarked=!1}callAfterTTI(e){this.ttiMarked?e():this._postTTICallbacks.push(e)}_triggerPostTTICallbacks(){for(const e of this._postTTICallbacks)e();this._postTTICallbacks=[]}markTTI(){clearTimeout(this.ttiTimeoutId),setTimeout((()=>{this.ttiMarked=!0,this._triggerPostTTICallbacks();const e=document.createEvent("Event");e.initEvent("TTI",!0,!0),window.dispatchEvent(e)}),0)}startTTITimeout(e,t){this.ttiTimeoutId=setTimeout((()=>{t&&t(),this._triggerPostTTICallbacks()}),e)}}function validateObjectProperties(e,t,s){for(const r of Object.keys(s)){if(!Object.prototype.hasOwnProperty.call(t,r))throw new Error(e+" missing required property '"+r+"'");let n,o=!1;const i=s[r];if(null!==i)if("object"==typeof i?(n=i.kind,o=i.nullable):n=i,o){if(null!=t[r]&&typeof t[r]!==n)throw new Error(e+" property '"+r+"' has incorrect type. Expected '"+n+"' or null, got '"+typeof t[r]+"'")}else{const s=typeof t[r];if(s!==n)throw new Error(e+" property '"+r+"' has incorrect type. Expected '"+n+"', got '"+s+"'")}}}function validatePageletConfig(e){if(null==e)throw new Error("Pagelet config is null or undefined")
blah blah and goes on and on.....
Greg-DB
Dropbox Community Moderator
2 years agoterryz 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.
About Dropbox API Support and Feedback
Get help with the Dropbox API from fellow developers and experts.
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!