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

"Unknown error occurred" when trying to add a new integration (after pvSystemId, keyid, keyvalue) #367

Open
RichardBeisser opened this issue Dec 3, 2024 · 11 comments

Comments

@RichardBeisser
Copy link

Hello,

after I got my pvSystemId, keyid and keyvalue, I tried to add a new integration with your HACS
I enter pvSystemId, keyid and keyvalue.
After some seconds, there is a message "Unknown error occurred"

Version of the custom_component

0.2.4

Debug log

by the way, what is the correct name of your HACS for Logger ?
custom_components.Fronius_Solarweb: info
or
custom_components.solarweb: info

For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_verify_locations
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 189, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, in _run_once
    handle._run()
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 556, in start
    task = asyncio.Task(coro, loop=loop, eager_start=True)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 477, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 567, in _handle
    return await handler(request)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 86, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
    return await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in async_configure
    result = await self._async_configure(flow_id, user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 414, in _async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 517, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
  File "/config/custom_components/solarweb/config_flow.py", line 38, in async_step_user
    info = await self._validate_input(user_input)
  File "/config/custom_components/solarweb/config_flow.py", line 83, in _validate_input
    client = Fronius_Solarweb(

2024-12-03 00:48:01.906 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/tenacity/asyncio/__init__.py", line 114, in __call__
    result = await fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/fronius_solarweb/api.py", line 120, in get_pvsystem_meta_data
    json_data = await self._check_api_response(r)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/fronius_solarweb/api.py", line 71, in _check_api_response
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/httpx/_models.py", line 763, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '403 Forbidden' for url 'https://api.solarweb.com/swqapi/pvsystems/15b86207anonymisiert'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 477, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 567, in _handle
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 86, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
    return await method(view, request, data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in async_configure
    result = await self._async_configure(flow_id, user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 414, in _async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 517, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/solarweb/config_flow.py", line 38, in async_step_user
    info = await self._validate_input(user_input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/solarweb/config_flow.py", line 87, in _validate_input
    system_data = await client.get_pvsystem_meta_data()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/tenacity/asyncio/__init__.py", line 189, in async_wrapped
    return await copy(fn, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/tenacity/asyncio/__init__.py", line 111, in __call__
    do = await self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/tenacity/asyncio/__init__.py", line 153, in iter
    result = await action(retry_state)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/tenacity/_utils.py", line 99, in inner
    return call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/tenacity/__init__.py", line 419, in exc_check
    raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x7f0f869cb320 state=finished raised HTTPStatusError>]
2024-12-03 00:48:10.258 INFO (SyncWorker_16) [pyfritzhome.fritzhome] Updating Devices ...



@drc38
Copy link
Owner

drc38 commented Dec 3, 2024

Have you confirmed your details work on the official Fronius test site?

@drc38
Copy link
Owner

drc38 commented Dec 3, 2024

custom_components.solarweb
The library it uses is:
fronius_solarweb

@RichardBeisser
Copy link
Author

Have you confirmed your details work on the official Fronius test site?
Yes.
The official app uses the same API and the same keyid and keyvalue ;-)

Can I send you my pvSystemId, keyid, keyvalue via Email?

Does your HACS act like the official app, with Cookies, Bearer-Token, etc.?

@drc38
Copy link
Owner

drc38 commented Dec 3, 2024

If you need help with access you need to contact Fronius directly

@RichardBeisser
Copy link
Author

RichardBeisser commented Dec 3, 2024

If you need help with access you need to contact Fronius directly

Access works.
I asked if you want my pvSystemId, keyid, keyvalue for testing
I dont want to publish it here, so i asked for your email

`GET https://swqapi.solarweb.com/info/user?details=accountAttributes,contractinformation HTTP/2.0
accesskeyid: FKIAB4CDA7anonym
accesskeyvalue: 67315e-anonym
content-type: application/json
authorization: Bearer eyJ4NXQiOiJOalpoT0anonym
accept-encoding: gzip
user-agent: okhttp/4.12.0

HTTP/2.0 401
content-type: application/json
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
referrer-policy: origin-when-cross-origin
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
content-security-policy: default-src 'self'
date: Mon, 02 Dec 2024 22:23:26 GMT
set-cookie: lbc=!WXhQrjsPASTKPCUDh2dzVc1rNXSSveiHbbdZAttLMczpV+4coTvjanonym=; path=/; Httponly; Secure
set-cookie: TS01f7cda4=015bdaa268772e0080612579f5345cd6ae5anonym; Path=/; Domain=.swqapi.solarweb.com

{"responseError":1113,"responseMessage":"JWT expired."}

GET https://swqapi.solarweb.com/info/user?details=accountAttributes,contractinformation HTTP/2.0
accesskeyid: FKIABanonym
accesskeyvalue: 67315e19-anonym
content-type: application/json
authorization: Bearer eyJ4NXQiOiJOalpoT0dJMVpqQXpaVGanonym
accept-encoding: gzip
user-agent: okhttp/4.12.0

GET https://swqapi.solarweb.com/pvsystems?limit=1000 HTTP/2.0
accesskeyid: FKIABanonym
accesskeyvalue: 67315e19-anonym
content-type: application/json
authorization: Bearer eyJ4NXQiOiJOalpoT0dJMVpqQXpaVGt5TlRVNU1anonym
accept-encoding: gzip
user-agent: okhttp/4.12.0
if-modified-since: Mon, 02 Dec 2024 20:32:51 GMT

HTTP/2.0 200
content-length: 1237
content-type: application/json; charset=utf-8
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
referrer-policy: origin-when-cross-origin
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
content-security-policy: default-src 'self'
x-rate-limit-limit: 1h
x-rate-limit-remaining: 29998
x-rate-limit-reset: 2024-12-02T23:00:00.0000000Z
date: Mon, 02 Dec 2024 22:23:27 GMT
set-cookie: lbc=!bAe8RNl1sh5oJdoDh2dzVc1rNXSSvZ5GNXx8jikclot/anonym=; path=/; Httponly; Secure
set-cookie: TS01f7cda4=015bdaa26807ec15fbb98ca9701ff53anonym; Path=/; Domain=.swqapi.solarweb.com

{"pvSystems":[{"pvSystemId":"15b86207-6115anonym","name":"Symo GEN24","address":{"country":"DE","zipCode":"12345","street":"strasse 1","city":"musterstadt","state":"BW"},"pictureURL":"https://froniussestimagesweprod.blob.core.windows.net/pvsystem-images/00000000-0000-0000-0000-000000000gekuerzt","peakPower":10560.0,"installationDate":"2024-09-03T17:35:54Z","lastImport":"2024-12-02T21:56:33Z","meteoData":"pro","timeZone":"Europe/Berlin"},{"pvSystemId":"d941ac4e-394anonym","name":"SymoAdvanced","address":{"country":"DE","zipCode":"12345","street":"strasse. 1","city":"musterhausen","state":"BW"},"pictureURL":"https://froniussestimagesweprod.blob.core.windows.net/pvsystem-images/00000000-0000-0000-0000-000000000000%2F2b697a87gekuerzt","peakPower":12000.0,"installationDate":"2024-09-18T08:03:34Z","lastImport":"2024-12-02T16:09:44Z","meteoData":"light","timeZone":"Europe/Berlin"}],"links":{"first":"https://swqapi.solarweb.com/pvsystems?offset=0&limit=1000","prev":null,"self":"https://swqapi.solarweb.com/pvsystems?offset=0&limit=1000","next":null,"last":"https://swqapi.solarweb.com/pvsystems?offset=0&limit=1000","totalItemsCount":2}}
`

@drc38
Copy link
Owner

drc38 commented Dec 3, 2024

Check your pydantic version in HA and check you're using the right release version of this integration to match.

@RichardBeisser
Copy link
Author

RichardBeisser commented Dec 3, 2024

Check your pydantic version in HA and check you're using the right release version of this integration to match.

How do I do this?

keyid and keyvalue are sniffed from traffic of official app, so it has to be correct

http://ha.local:8123/config/info
shows:
Core 2024.11.3 Supervisor 2024.11.4 Operating System 13.2 Frontend 20241106.2

@RichardBeisser
Copy link
Author

Yesterday, I updated to
Core 2025.1.0 Supervisor 2024.12.3 Operating System 14.1 Frontend 20250103.0 ⸱ legacy
I reinstalled your HACS V0.3.2
The problem exists without any change.

I checked the keyid and keyvalue which is used within the official app. They are still the same.
With these "credentials", at the Fronius API-Test-site, i can successfully create a Bearer token.
With this token + keyid and keyvalue, I can execute any get-requests successfully

@drc38
Copy link
Owner

drc38 commented Jan 4, 2025

This integration does not support using a bearer token. If someone creates a PR to include this I'll incorporate it.

@RichardBeisser
Copy link
Author

This integration does not support using a bearer token.

You asked if I have tested keyid, keyvalue at Fronius test-page. At Testpage, you only get status "authorized" when you have entered 3 things: keyid, keyvalue and bearer token.
I tested different get-commands at testpage. I only get the correct vallues when I provide keyid, keyvalue and bearer token.
The only thing which works without a bearer token is creating a token

Do you really have a keyid and keyvalue which work at Testpage without a bearer token?
I can't imagine that this works. The result would be that at the moment nobody can use your HACS

@drc38
Copy link
Owner

drc38 commented Jan 5, 2025

Yes, using the keyid and keyvalue you create on Solarweb once given access by Fronius to the api works fine. Unfortunately I don't have time or the requirement to look at how to amend the codebase to use a bearer key instead.

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