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

UE32J5200 - Handshake status 400 Bad Request when trying to get token #62

Closed
EPMatt opened this issue Nov 22, 2020 · 8 comments
Closed

Comments

@EPMatt
Copy link

EPMatt commented Nov 22, 2020

Hi @sermayoral,
I'm trying to connect a UE32J5200 TV with this integration. Unfortunately I'm stuck at the token retrieval.

Running get_token.py --ip <myip> --port 8080 results in a connection refused error.
I found that the procedure defined in connect() method of the PySmartCrypto library is using the hardcoded port 8000, so that the port supplied via cli argument is not considered in the pairing section.

This issue has been addressed in #61, but I still can't connect to my device.
Running get_token.py --ip <myip> --port 8080 on the PR #61 results in a different error:

Traceback (most recent call last):
  File "get_token.py", line 40, in <module>
    main(sys.argv[1:])
  File "get_token.py", line 36, in main
    PySmartCrypto(ip, port)
  File "[omitted]/ha-samsungtv-encrypted/custom_components/samsungtv_encrypted/PySmartCrypto/pysmartcrypto.py", line 123, in __init__
    self._connection = self.connect()
  File "[omitted]/ha-samsungtv-encrypted/custom_components/samsungtv_encrypted/PySmartCrypto/pysmartcrypto.py", line 99, in connect
    connection = websocket.create_connection(websocket_url)
  File "[omitted]/lib/python3.6/site-packages/websocket/_core.py", line 515, in create_connection
    websock.connect(url, **options)
  File "[omitted]/lib/python3.6/site-packages/websocket/_core.py", line 226, in connect
    self.handshake_response = handshake(self.sock, *addrs, **options)
  File "[omitted]/lib/python3.6/site-packages/websocket/_handshake.py", line 80, in handshake
    status, resp = _get_resp_headers(sock)
  File "[omitted]/lib/python3.6/site-packages/websocket/_handshake.py", line 165, in _get_resp_headers
    raise WebSocketBadStatusException("Handshake status %d %s", status, status_message, resp_headers)
websocket._exceptions.WebSocketBadStatusException: Handshake status 400 Bad Request

I tried to debug the issue by myself without success, but I discovered that the value of websocket_response after its initialization is <Response [403]>, while the value of websocket_urlafter its initialization is

ws://<myip>:8080/socket.io/1/websocket/<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http

which I think it's not what it should be.

So the problem seems to be with the first request receiving a Forbidden response at line 95.
I'd be glad to help you solving this issue. 👍🏻

@estevez-dev
Copy link

I have the same issue with UE55H6203AK model.
I'm also getting <Response [403]>

I've tried everything from #61 with reverting latest fixes, changing the port to 8000, but still no luck.

@EPMatt
Copy link
Author

EPMatt commented Dec 1, 2020

Hi @estevez-dev,
could you please post the command you used for retrieving the token, and the output you received?

@estevez-dev
Copy link

Hi @EPMatt
Sure.
I'm using:

python3 ./get_token.py --ip 192.168.2.23 --port 8080

and getting:

<Response [403]>
Traceback (most recent call last):
  File "./get_token.py", line 40, in <module>
    main(sys.argv[1:])
  File "./get_token.py", line 36, in main
    PySmartCrypto(ip, port)
  File "/home/estevez/src/ha-samsungtv-encrypted/custom_components/samsungtv_encrypted/PySmartCrypto/pysmartcrypto.py", line 124, in __init__
    self._connection = self.connect()
  File "/home/estevez/src/ha-samsungtv-encrypted/custom_components/samsungtv_encrypted/PySmartCrypto/pysmartcrypto.py", line 100, in connect
    connection = websocket.create_connection(websocket_url)
  File "/home/estevez/.local/lib/python3.7/site-packages/websocket/_core.py", line 515, in create_connection
    websock.connect(url, **options)
  File "/home/estevez/.local/lib/python3.7/site-packages/websocket/_core.py", line 226, in connect
    self.handshake_response = handshake(self.sock, *addrs, **options)
  File "/home/estevez/.local/lib/python3.7/site-packages/websocket/_handshake.py", line 80, in handshake
    status, resp = _get_resp_headers(sock)
  File "/home/estevez/.local/lib/python3.7/site-packages/websocket/_handshake.py", line 165, in _get_resp_headers
    raise WebSocketBadStatusException("Handshake status %d %s", status, status_message, resp_headers)
websocket._exceptions.WebSocketBadStatusException: Handshake status 400 Bad Request

Should I add this info to #21 as well?

@EPMatt
Copy link
Author

EPMatt commented Dec 1, 2020

Hi @estevez-dev,
could you please try to execute the following command? Switching to port 8000.

python3 ./get_token.py --ip 192.168.2.23 --port 8000

@estevez-dev
Copy link

Hi @EPMatt
I'm getting Connection refused when trying to use 8000 in any case.
I tried like this:

python3 ./get_token.py --ip 192.168.2.23 --port 8000

I also tried to hardcode 8000 in connect function for step4_url, for websocket_url and for both. The answer is always the same:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.2.23', port=8000): Max retries exceeded with url: /socket.io/1/?t=1606845620690 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ae57b664748>: Failed to establish a new connection: [Errno 111] Connection refused'))

So looks like 8000 is not an option for my TV as well.

@EPMatt
Copy link
Author

EPMatt commented Dec 2, 2020

Hi @estevez-dev,
sorry for my delayed response. Could you please try to run the following command and post its entire output? So we can check which ports are opened on your TV.

nmap <your_ip>

Moreover, If you'd like we can move this issue to #21 and keep track of the progress there. :)

@EPMatt
Copy link
Author

EPMatt commented Dec 3, 2020

Moved to #21.

@EPMatt EPMatt closed this as completed Dec 3, 2020
@Ramias1
Copy link

Ramias1 commented Jan 26, 2024

getting the same thing with my J6200

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

3 participants