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

error 404 when trying to download a file. #2084

Closed
Buddyboy-git opened this issue Jan 1, 2024 · 3 comments
Closed

error 404 when trying to download a file. #2084

Buddyboy-git opened this issue Jan 1, 2024 · 3 comments

Comments

@Buddyboy-git
Copy link

Package

dio

Version

5.5.0

Operating-System

Windows

Output of flutter doctor -v

[√] Flutter (Channel stable, 3.16.3, on Microsoft Windows [Version 10.0.22621.2861], locale en-US)
    • Flutter version 3.16.3 on channel stable at D:\Program Files\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b0366e0a3f (4 weeks ago), 2023-12-05 19:46:39 -0800
    • Engine revision 54a7145303
    • Dart version 3.2.3
    • DevTools version 2.28.4

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at D:\Program Files\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: D:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.19)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
    • Visual Studio Build Tools 2019 version 16.11.32901.82
    • Windows 10 SDK version 10.0.18362.0

[√] Android Studio (version 2023.1)
    • Android Studio at D:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)

[√] VS Code (version 1.85.1)
    • VS Code at C:\Users\miket\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.80.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22621.2861]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 120.0.6099.130
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 120.0.2210.91

[√] Network resources
    • All expected network resources are available.

• No issues found!
PS D:\Users\miket\Flutter_Projects\flutter_http_app\flutter_http_app> flutter doctor -v
[√] Flutter (Channel stable, 3.16.3, on Microsoft Windows [Version 10.0.22621.2861], locale en-US)
    • Flutter version 3.16.3 on channel stable at D:\Program Files\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b0366e0a3f (4 weeks ago), 2023-12-05 19:46:39 -0800
    • Engine revision 54a7145303
    • Dart version 3.2.3
    • DevTools version 2.28.4

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at D:\Program Files\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: D:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.19)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
    • Visual Studio Build Tools 2019 version 16.11.32901.82
    • Windows 10 SDK version 10.0.18362.0

[√] Android Studio (version 2023.1)
    • Android Studio at D:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)

[√] VS Code (version 1.85.1)
    • VS Code at C:\Users\miket\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.80.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22621.2861]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 120.0.6099.130
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 120.0.2210.91

[√] Network resources
    • All expected network resources are available.

• No issues found!

Dart Version

3.2.3

Steps to Reproduce

Using a browser. I can login to a server. Navigate to file download. and download a .csv file.
However, when I use dio.download:
I can login succesfully.
I can navigate successfully.
But when I try to download the same csv file I get error 404 status code and the local file gets created with the html code for the 404.

I did successfully download a file from a test server that doesn't require authentication.

The authenticated server uses cookies authentication.

My Code is below.
`
import 'package:cookie_jar/cookie_jar.dart';
import 'package:dio/dio.dart';
import 'package:dio_cookie_manager/dio_cookie_manager.dart';

const username = '[email protected]';
const password = 'monkey';
const baseUrl = 'https://require_basic_auth.com';
const endpointUrl = 'pricingdata/thumasteritems-current.csv?v=2';
const allpricesUrl = 'https://requires_basic_auth.com/current-pricing/';
const localsavePath = "new-thumasteritems-current.csv";

void main() async {
var dio = Dio(BaseOptions(
connectTimeout: const Duration(seconds: 10), // in ms
receiveTimeout: const Duration(seconds: 10),
sendTimeout: const Duration(seconds: 10),
responseType: ResponseType.plain,
followRedirects: true,
validateStatus: (status) {
return true;
})); // some dio configurations

dio.interceptors.add(CookieManager(CookieJar()));

//var firstResponse = await dio.get(baseUrl);
//print(firstResponse.statusCode);

var loginResponse = await dio.post(baseUrl,
data: FormData.fromMap({
'username': username,
'password': password,
})); // cookies are automatically saved
print(loginResponse.statusCode);

const endpointUrl = 'https://proof.ovh.net/files/1Mb.dat'; // test server - works.

try {
var dlresponse = await dio.download(endpointUrl, localsavePath);
print(dlresponse.statusCode);
print('Download complete!');
} catch (e) {
print('Error during download: $e');
}

}

`

Expected Result

I was expecting a file to be downloaded.

Actual Result

I local file gets created with the contents of Error 404 html.

@Buddyboy-git Buddyboy-git added h: need triage This issue needs to be categorized s: bug Something isn't working labels Jan 1, 2024
@AlexV525
Copy link
Member

AlexV525 commented Jan 2, 2024

Please provide a minimal reproducible example.

@AlexV525 AlexV525 added the h: need more info Further information is requested label Jan 2, 2024
@kuhnroyal
Copy link
Member

Please format your code.

You have configured the validateStatus callback to always return true and so every response is treated as success. That's why the file is being downloaded independent of the status code.

@Buddyboy-git
Copy link
Author

Yes. Sorry. I meant to get back here earlier. The code above is about the 20th version.
But the ValidateStatus isn't the issue either even though it is being used incorrectly...
I am logging in successful reguardless of that parameter. status 200 has proved that in other attempts.
Plus I went out an duplicated this issue in a Python script also last night.
The website uses iFrames which is probably contributing to the difficulty of my scripts not maintaining persistance.
I will probably skip this part of the project until I get further along and then contact the site developer for a little guidance.
I'm pretty sure I'm missing a simple header parameter. I loaded up the Python request with a bunch of headers including User-Agent, but it's still a no go.
I haven't capture a cookie or a token manually yet to be able to send back on my 2nd request. I don't feel too bad, because DIO and other HTTP packages can't either.

Sorry to waste your time by opening this issue.

@AlexV525 AlexV525 added i: not related and removed h: need more info Further information is requested h: need triage This issue needs to be categorized s: bug Something isn't working labels Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants