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

WebSocketException: Connection not upgraded to websocket #321

Open
austin047 opened this issue Jan 14, 2024 · 4 comments
Open

WebSocketException: Connection not upgraded to websocket #321

austin047 opened this issue Jan 14, 2024 · 4 comments

Comments

@austin047
Copy link

I am attempting to connect to a WebSocket API delivered via the AWS API gateway, currently, I am able to establish a successful connection via PostMan and Python scripts ran from my local terminal, but when I attempt a connection with dart I keep getting this error of WebSocketException: Connection was not upgraded to websocket

My code

main() async {
  final wsUrl = Uri.parse('wss://xxxxxxxxxx.execute-api.eu-west-1.amazonaws.com/qa');
  final channel = IOWebSocketChannel.connect(wsUrl);

  // await channel.ready;

  channel.stream.listen((message) {
    print(message);
    channel.sink.add('received!');
  });
}

Error:

Unhandled exception:
WebSocketChannelException: WebSocketChannelException: WebSocketException: Connection to 'https://xxxxxxxxxx.execute-api.eu-west-1.amazonaws.com:0/qa#' was not upgraded to websocket
#0      new IOWebSocketChannel._withoutSocket.<anonymous closure> (package:web_socket_channel/io.dart:98:24)
#1      Stream.handleError.<anonymous closure> (dart:async/stream.dart:931:16)
#2      _HandleErrorStream._handleError (dart:async/stream_pipe.dart:269:17)
#3      _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:157:13)
#4      _RootZone.runBinaryGuarded (dart:async/zone.dart:1606:10)
#5      _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:358:15)
#6      _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:376:7)
#7      _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:280:7)
#8      _SyncStreamControllerDispatch._sendError (dart:async/stream_controller.dart:788:19)
#9      _StreamController._addError (dart:async/stream_controller.dart:666:7)
#10     _RootZone.runBinaryGuarded (dart:async/zone.dart:1606:10)
#11     _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:358:15)
#12     _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:376:7)
#13     _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:280:7)
#14     _SyncStreamControllerDispatch._sendError (dart:async/stream_controller.dart:788:19)
#15     _StreamController._addError (dart:async/stream_controller.dart:666:7)
#16     new Stream.fromFuture.<anonymous closure> (dart:async/stream.dart:253:18)
#17     _RootZone.runBinary (dart:async/zone.dart:1666:54)
#18     _FutureListener.handleError (dart:async/future_impl.dart:177:22)
#19     Future._propagateToListeners.handleError (dart:async/future_impl.dart:858:47)
#20     Future._propagateToListeners (dart:async/future_impl.dart:879:13)
#21     Future._completeError (dart:async/future_impl.dart:655:5)
#22     Future._asyncCompleteError.<anonymous closure> (dart:async/future_impl.dart:745:7)
#23     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#24     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#25     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#26     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:405:11)
#27     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
#28     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Any help on this will be much appreciated

@Avril1
Copy link

Avril1 commented Jan 15, 2024

Please check your server is opening first.
I had the same issue, finally I found that the server was closed.

@austin047
Copy link
Author

My server in current up and running, I am able to create a websocket connection via the Postman client and a python script, but not Dart.

@Avril1
Copy link

Avril1 commented Jan 15, 2024

Have you tried this way? I'm using WebSocketChannel.connect(wsUrl).

@austin047
Copy link
Author

Yes I have tried that before, it's work aswell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants