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

Expected template to be a string - Multiscrape can not be setup #312

Closed
pdevick opened this issue Jan 4, 2024 · 6 comments · Fixed by #313
Closed

Expected template to be a string - Multiscrape can not be setup #312

pdevick opened this issue Jan 4, 2024 · 6 comments · Fixed by #313

Comments

@pdevick
Copy link

pdevick commented Jan 4, 2024

Since this morning my multiscrape integration does not work anymore. I did not change anything in the configuration.
The changes where upgrading multiscrape to the latest and home assistant to the latest

Multitscrape version 6.8.0
HA 2024.1

I tried to revert the multiscrape to the previous version but did not work out and not help in getting rid of the message. I also tried to minimize the number of sensors defined in the configuration. Just only a resource and a simple sensor.

The message in the loggs of HA provide the following information

Logger: homeassistant.setup
Source: setup.py:332
First occurred: 11:04:26 (1 occurrences)
Last logged: 11:04:26

Error during setup of component multiscrape
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 332, in _async_setup_component
result = await task
^^^^^^^^^^
File "/config/custom_components/multiscrape/init.py", line 89, in async_setup
return await _async_process_config(hass, entry)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/multiscrape/init.py", line 151, in _async_process_config
http = _create_scrape_http_wrapper(config_name, conf, hass, file_manager)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/multiscrape/init.py", line 237, in _create_scrape_http_wrapper
headers_renderer=create_dict_renderer(hass, headers)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/multiscrape/util.py", line 36, in create_dict_renderer
templates_dict[item] = create_renderer(hass, templates_dict[item])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/multiscrape/util.py", line 15, in create_renderer
value_template = Template(value_template, hass)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 469, in init
raise TypeError("Expected template to be a string")
TypeError: Expected template to be a string

@pdevick
Copy link
Author

pdevick commented Jan 4, 2024

The example provided with the components works well. The difference is that i use a form submit to authenticate before scraping.

form_submit: &form_submit_template
  submit_once: true
  resource: "https://xxx.xxx.xxx/login?ut=user"
  input:
    username: "xxxx"
    password: "xxxx"
  resubmit_on_error: true #check if there is no hickup anymore in the timeline

Then it states again string expected.

@pdevick pdevick changed the title Expected template to be a string - Multiscape can not be setup Expected template to be a string - Multiscrape can not be setup Jan 4, 2024
@IceDraken
Copy link

I am getting the same since doing the update to home assistant.

This is my error log, and it looks to be the same as yours.

Logger: homeassistant.setup
Source: setup.py:332
First occurred: 7:47:54 AM (1 occurrences)
Last logged: 7:47:54 AM

Error during setup of component multiscrape
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 332, in _async_setup_component
result = await task
^^^^^^^^^^
File "/config/custom_components/multiscrape/init.py", line 89, in async_setup
return await _async_process_config(hass, entry)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/multiscrape/init.py", line 151, in _async_process_config
http = _create_scrape_http_wrapper(config_name, conf, hass, file_manager)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/multiscrape/init.py", line 237, in _create_scrape_http_wrapper
headers_renderer=create_dict_renderer(hass, headers)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/multiscrape/util.py", line 36, in create_dict_renderer
templates_dict[item] = create_renderer(hass, templates_dict[item])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/multiscrape/util.py", line 15, in create_renderer
value_template = Template(value_template, hass)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 467, in init
raise TypeError("Expected template to be a string")
TypeError: Expected template to be a string

@pdevick
Copy link
Author

pdevick commented Jan 4, 2024

I have found a solution for me. I followed the code in the stacktrace and swa it was happening at reading headers from the config. I removed my part of the configuration (which worked for a long time before) and it is working again.

- resource: !resource_link
 name: name
 log_response: false
 scan_interval: 120
 headers:
   User-Agent: Mozilla/5.0

I removed the headers part and it is working for now. Still i am in favour of having headers so a structural solution is preferred.

@mjtappert
Copy link

Same error for me on this version of Multiscrape and HA.

@briadelour
Copy link

briadelour commented Jan 4, 2024

I can confirm what @bios2bios reported. I just commented out the headers section and restarted and multiscrape worked again.

@palafix
Copy link

palafix commented Jan 4, 2024

Maybe someone knows how to make a template - list because this section has changed from string - list to template - list.

headers - The headers for the requests. - False - template - list

I dont know how to do.

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

Successfully merging a pull request may close this issue.

5 participants