Dart fails to parse the www-authenticate response header.
For example:
The result of curl -i -X POST https://api.thetvdb.com/login is:
HTTP/2 401
date: Mon, 29 Jul 2019 09:15:50 GMT
content-type: application/json; charset=utf-8
content-length: 26
set-cookie: __cfduid=d0a0c5ee3934fe0f08c3ddd136ab53e471564391749; expires=Tue, 28-Jul-20 09:15:49 GMT; path=/; domain=.thetvdb.com; HttpOnly
vary: Accept-Language
www-authenticate: JWT realm=jwt auth
x-powered-by: Thundar!
x-thetvdb-api-version: 2.2.0
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 4fddfd9498b5c2c2-FRA
{"Error":"Not authorized"}
When I try to run the same using dart, I get an exception
import 'dart:io';
Future main() async {
var httpClient = HttpClient();
var request = await httpClient.postUrl(Uri.parse('https://api.thetvdb.com/login'));
await request.close();
httpClient.close();
}
HttpException: Failed to parse header value
#0 _HeaderValue._parse.expect (dart:_http/http_headers.dart:684:9)
#1 _HeaderValue._parse.parseParameters (dart:_http/http_headers.dart:764:15)
#2 _HeaderValue._parse (dart:_http/http_headers.dart:773:20)
#3 _HeaderValue.parse (dart:_http/http_headers.dart:626:12)
#4 _HttpClientResponse._authenticate (dart:_http/http_impl.dart:476:22)
#5 _HttpClientRequest._onIncoming (dart:_http/http_impl.dart:1093:25)
#6 _HttpClientConnection.send.<anonymous closure>.<anonymous closure> (dart:_http/http_impl.dart:1741:17)
#7 _RootZone.runUnary (dart:async/zone.dart:1379:54)
#8 _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
#9 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
#10 Future._propagateToListeners (dart:async/future_impl.dart:668:32)
#11 Future._completeWithValue (dart:async/future_impl.dart:483:5)
#12 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:513:7)
#13 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#14 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#15 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:391:30)
#16 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
#17 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Is there any way around this? I don't know if the header value is valid or not, but it seems to be that even in case of an invalid response header callers should be able to get the 401 response back and not end up with an exception.
Am I doing something wrong?
Thanks,
Itay
Related
I just updated my dart application and did a pub cache repair afterwards.
The application does not run and debug throws the following exception
Uncaught Unhandled exception:
Unsupported operation: Cannot provide `reflectedType` of instance of generic type 'List'.
#0 InstantiatedGenericClassMirrorImpl.reflectedType (package:reflectable/src/reflectable_transformer_based.dart:713:5)
#1 _getPropertyInfoForType (package:polymer/src/common/polymer_descriptor.dart:210:46)
#2 _buildPropertiesObject.<anonymous closure> (package:polymer/src/common/polymer_descriptor.dart:58:24)
#3 _HashVMBase&MapMixin&&_LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:340)
#4 _buildPropertiesObject (package:polymer/src/common/polymer_descriptor.dart:56:16)
#5 createPolymerDescriptor (package:polymer/src/common/polymer_descriptor.dart:26:19)
#6 PolymerRegister.initialize (package:polymer/src/common/polymer_register.dart:19:36)
#7 loadInitializers.<anonymous closure>.<anonymous closure> (package:initialize/src/static_loader.dart:46:32)
#8 _runInitQueue (package:initialize/initialize.dart:35:24)
#9 _runInitQueue.<anonymous closure> (package:initialize/initialize.dart:38:26)
#10 _RootZone.runUnary (dart:async/zone.dart:1149)
#11 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:502)
#12 _Future._propagateToListeners (dart:async/future_impl.dart:585)
#13 _Future._completeWithValue (dart:async/future_impl.dart:376)
#14 _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:430)
#15 _microtaskLoop (dart:async/schedule_microtask.dart:43)
#16 _microtaskLoopEntry (dart:async/schedule_microtask.dart:52)
#17 _ScheduleImmediateHelper._handleMutation (dart:html:49254)
#18 MutationObserver._create.<anonymous closure> (dart:html:27526)
(anonymous function)
The application was running quite well before.
Possible bug?
Thanks
Teddy
Rather long story, please check https://github.com/dart-lang/polymer-dart/issues/651 for some details, and for the resolution of this issue as it unfolds.
I'm following the Getting Started with Flutter guide and getting stuck when running the actual flutter command:
flutter init -o my_app
Resolving dependencies...
Error on line 17, column 16 of pubspec.yaml: Invalid version constraint: Could not parse version "^1.4.0". Unknown text at "^1.4.0".
stack_trace: ^1.4.0
^^^^^^
Unhandled exception:
Uncaught Error: FileSystemException: Cannot open file, path = '/Users/craig/Code/flutter/packages/flutter_tools/packages/sky_tools/executable.dart' (OS Error: No such file or directory, errno = 2)
Stack Trace:
#0 _File.open.<anonymous closure> (dart:io/file_impl.dart:349)
#1 _RootZone.runUnary (dart:async/zone.dart:1151)
#2 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:496)
#3 _Future._propagateToListeners (dart:async/future_impl.dart:579)
#4 _Future._completeWithValue (dart:async/future_impl.dart:339)
#5 _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:401)
#6 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#7 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#8 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:84)
#9 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:131)
#0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:883)
#1 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#2 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#3 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:84)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:131)
Unhandled exception:
Uncaught Error: FileSystemException: Cannot open file, path = '/Users/craig/Code/flutter/bin/cache/flutter_tools.snapshot' (OS Error: No such file or directory, errno = 2)
Stack Trace:
#0 _File.open.<anonymous closure> (dart:io/file_impl.dart:349)
#1 _RootZone.runUnary (dart:async/zone.dart:1151)
#2 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:496)
#3 _Future._propagateToListeners (dart:async/future_impl.dart:579)
#4 _Future._completeWithValue (dart:async/future_impl.dart:339)
#5 _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:401)
#6 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#7 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#8 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:84)
#9 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:131)
#0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:883)
#1 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#2 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#3 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:84)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:131)
Looks like your Dart version is outdated < 1.9.2.
Try dart --version to get the version of your installed Dart SDK.
Current is 1.12.x.
Update 2018-03-20
During the migration phase to Dart 2 you might want to install Dart from the dev channel to get a 2.0.0-alpha.x version.
The newest stable version is 1.24.x
For example
brew install dart --devel
Update 2018-06-21
Now also supported:
brew install dart#2
For others who're facing a similar error, I suggest that you read the docs carefully. I didn't, hence I wasted quite some time looking out for the solution elsewhere, even though it was right in front of my eyes all the time: https://flutter.io/setup-macos/#update-your-path
I'm writing the commands down so that you can copy and paste them easily in your terminal window:
touch $HOME/.bash_profile
open $HOME/.bash_profile
Line 1 creates a text file named .bash_profile. Line 2 opens it.
Then the line given below has to be pasted in the text file:
export PATH=[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin:$PATH
Don't forget to save the file after pasting. flutter doctor should work with every Terminal window now.
Open your terminal and run this
export PATH=[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin:$PATH
then run flutter, it will work.
It's because you the path you set up is temporary. To add the path
export PATH=[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin:$PATH
[PATH_TO_FLUTTER_GIT_DIRECTORY] -> Folder where you downloaded flutter or cloned from git.
Then do
echo $PATH
Watch this video to easy install
https://www.youtube.com/watch?v=Em8igImhBKc
I test my app on AngularDart v0.14.0 pub server but it has error
Exception: Uncaught Error: Type 'CurrencyService' not found in generated typeFactory maps. Is the type's constructor injectable and annotated for injection?
Stack Trace:
#0 GeneratedTypeFactories.parameterKeysFor (package:di/src/reflector_static.dart:26:5)
#1 Binding.bind (package:di/src/module.dart:61:49)
#2 Module.bindByKey (package:di/src/module.dart:136:17)
#3 Module.bind (package:di/src/module.dart:124:14)
#4 CERPModule.CERPModule (http://localhost:8080/index.dart:71:9)
#5 main.<anonymous closure> (http://localhost:8080/index.dart:59:201)
#6 _RootZone.runUnary (dart:async/zone.dart:1082)
#7 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:488)
#8 _Future._propagateToListeners (dart:async/future_impl.dart:571)
#9 _Future._completeWithValue (dart:async/future_impl.dart:331)
#10 _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:393)
#11 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:41)
#12 _asyncRunCallback (dart:async/schedule_microtask.dart:48)
#13 _handleMutation (dart:html:39006)
When run in localhost:3030 this error don't occur.
Here is my Module
class CERPModule extends Module {
...
bind(CurrencyService);
...
}
Here is my CurrencyService
library cerp_currency_service;
import 'dart:async';
import 'dart:convert';
import 'package:angular/angular.dart';
class CurrencyService {
Http _http;
CurrencyService (Http this._http);
...
}
As far as I know you need to add the #Injectable annotation to your CurrencyService class.
#Injectable()
class CurrencyService {
I tried to install the dependencies for the polymer-dart-blog with 'pub get' but unfortunately this operation failed. I have absolutely no idea what the problem is. The ouput looks like this:
C:\Users\fraherm\workspace\polymer-dart-blog>pub get
Resolving dependencies..........................................................
................................................................................
................................................................................
................................................................Error in PubHttp
Client.send (issue 12581) error: HttpException: Connection closed before full he
ader was received, uri = https://pub.dartlang.org/api/packages/unittest/versions
/0.8.10%2B3
stacktrace: #0 PubHttpClient.send (file:///e:/b/build/slave/dart-editor
-win-stable/build/dart/sdk/lib/_internal/pub/lib/src/http.dart:60)
#1 BaseClient._sendUnstreamed.<anonymous closure> (package:http/src/base_cl
ient.dart:118)
#2 _Future._propagateToListeners.<anonymous closure> (dart:async/future_imp
l.dart:453)
#3 _rootRun (dart:async/zone.dart:683)
#4 _RootZone.run (dart:async/zone.dart:823)
#5 _Future._propagateToListeners (dart:async/future_impl.dart:445)
#6 _Future._complete (dart:async/future_impl.dart:303)
#7 _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:
354)
#8 _asyncRunCallback (dart:async/schedule_microtask.dart:18)
#9 _createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:11)
#10 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:151)
#11 _Timer._createTimerHandler.<anonymous closure> (timer_impl.dart:166)
#12 _RawReceivePortImpl._handler (dart:isolate-patch/isolate_patch.dart:1)
#13 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dar
t:93)
Connection closed before full header was received
Maybe you may just wait a while and then try again as
Seth explains in pub install -> HttpParserException: Connection closed before full header was received
Seems to be a problem with the server.
When i run the build.dart of my Web Component, the out folder is not created and i receive this error:
SEVERE web/main.html: exception while reading file, original message:
AsyncError: ''package:html5lib/dom.dart': Error: line 91 pos 51: type 'LinkedHashMap' is not loaded
LinkedHashMap<dynamic, String> attributes = new LinkedHashMap();
malformed type used.'
Stack trace:
#0 Node.Node (package:html5lib/dom.dart:91:51)
#1 Document.Document (package:html5lib/dom.dart:313:16)
#2 TreeBuilder.reset (package:html5lib/src/treebuilder.dart:100:16)
#3 TreeBuilder.TreeBuilder (package:html5lib/src/treebuilder.dart:87:10)
#4 HtmlParser.HtmlParser (package:html5lib/parser.dart:148:38)
#5 parseHtml (package:web_ui/src/compiler.dart:34:16)
#6 Compiler._parseHtmlFile.<anonymous closure>.<anonymous closure> (package:web_ui/src/compiler.dart:165:28)
#7 time (package:web_ui/src/utils.dart:38:24)
#8 Compiler._time (package:web_ui/src/compiler.dart:297:16)
#9 Compiler._parseHtmlFile.<anonymous closure> (package:web_ui/src/compiler.dart:164:32)
#10 _ThenFuture._sendValue (dart:async:372:24)
Has anyone the same problem?
Update: thanks for answers. However, i run pub update and now if i run build.dart file the result is:
Uncaught Error: NoSuchMethodError : method not found: 'innerHTML'
Receiver: Instance of 'Element'
Arguments: []
Stack Trace:
#0 Object.noSuchMethod (dart:core-patch:1743:25)
#1 _ElementLoader.visitScriptElement (package:web_ui/src/analyzer.dart:879:16)
#2 _ElementLoader.visitElement (package:web_ui/src/analyzer.dart:770:40)
#3 TreeVisitor.visit (package:html5lib/dom_parsing.dart:208:50)
#4 TreeVisitor.visitChildren (package:html5lib/dom_parsing.dart:220:49)
#5 TreeVisitor.visitNodeFallback (package:html5lib/dom_parsing.dart:228:48)
#6 TreeVisitor.visitElement (package:html5lib/dom_parsing.dart:237:50)
#7 _ElementLoader.visitElement (package:web_ui/src/analyzer.dart:777:34)
#8 TreeVisitor.visit (package:html5lib/dom_parsing.dart:208:50)
#9 TreeVisitor.visitChildren (package:html5lib/dom_parsing.dart:220:49)
#10 TreeVisitor.visitNodeFallback (package:html5lib/dom_parsing.dart:228:48)
#11 TreeVisitor.visitElement (package:html5lib/dom_parsing.dart:237:50)
#12 _ElementLoader.visitElement (package:web_ui/src/analyzer.dart:777:34)
#13 TreeVisitor.visit (package:html5lib/dom_parsing.dart:208:50)
#14 TreeVisitor.visitChildren (package:html5lib/dom_parsing.dart:220:49)
#15 TreeVisitor.visitNodeFallback (package:html5lib/dom_parsing.dart:228:48)
#16 TreeVisitor.visitDocument (package:html5lib/dom_parsing.dart:230:52)
#17 TreeVisitor.visit (package:html5lib/dom_parsing.dart:212:52)
#18 analyzeDefinitions (package:web_ui/src/analyzer.dart:33:15)
#19 Compiler._parseAndDiscover.processHtmlFile.<anonymous closure> (package:web_ui/src/compiler.dart:123:35)
#20 time (package:web_ui/src/utils.dart:38:24)
#21 Compiler._time (package:web_ui/src/compiler.dart:291:16)
#22 Compiler._parseAndDiscover.processHtmlFile (package:web_ui/src /compiler.dart:122:27)
#23 _ThenFuture._sendValue (dart:async:372:24)
I just went through this. It's because the packages you have, haven't been updated. Make sure you are using latest versions of every package, and run pub update.
In my case, I was using an older version of web-ui, which used an older version of html5lib package. I updated web-ui and things worked.
And like Florian said in the other answer, it's caused by a class which has moved to another library.
I recently moved 'LinkedHashMap' from dart:core into dart:collection.
The code you are showing still expects it in core.
Try to find an updated version of the html5lib package (maybe the mailing-list knows where you can download one).
Bob is currently working on versioning the dart-sdk in pub. So hopefully this shouldn't be such a problem in the future.