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

[Bug]: weather_status widget unable to retrieve osm location data due to invalid API endpoint #40540

Closed
5 of 8 tasks
ds4a opened this issue Sep 20, 2023 · 8 comments
Closed
5 of 8 tasks
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 26-feedback bug feature: dashboard

Comments

@ds4a
Copy link

ds4a commented Sep 20, 2023

⚠️ This issue respects the following points: ⚠️

Bug description

When entering an address in the weather_status dashboard widget an error is generated and the requested weather info is not changed, the widget weather location is not updated.
Dashboard displays "There was an error setting the location address."

Steps to reproduce

  1. On main NC dashboard, click on weather status widget.
  2. Enter new location in 'Set Custom Address' text box and submit.

Expected behavior

New weather location is displayed and set in widget, ability to save as favourite if desired.

Installation method

Community Manual installation with Archive

Nextcloud Server version

26

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.1

Web server

Apache (supported)

Database engine version

PostgreSQL

Is this bug present after an update or on a fresh install?

Fresh Nextcloud Server install

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

What user-backends are you using?

  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other

Configuration report

{
    "system": {
        "config_is_read_only": true,
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "my.domain.uk",
            "nextcloud.local"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "pgsql",
        "version": "26.0.5.1",
        "overwrite.cli.url": "http:\/\/newinstall.plusdrive.uk",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "maintenance": false,
        "mail_smtpmode": "smtp",
        "mail_smtpsecure": "ssl",
        "mail_sendmailmode": "smtp",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpauthtype": "PLAIN",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "465",
        "default_phone_region": "+44",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpauth": 1,
        "memcache.local": "\\OC\\Memcache\\APCu",
        "updater.secret": "***REMOVED SENSITIVE VALUE***",
        "theme": "",
        "loglevel": 2,
        "appstoreenabled": true
    }
}

List of activated Apps

Enabled:
  - activity: 2.18.0
  - admin_audit: 1.16.0
  - bruteforcesettings: 2.6.0
  - calendar: 4.5.0
  - circles: 26.0.0
  - cloud_federation_api: 1.9.0
  - comments: 1.16.0
  - contacts: 5.4.0
  - contactsinteraction: 1.7.0
  - dashboard: 7.6.0
  - dav: 1.25.0
  - external: 5.1.1
  - federatedfilesharing: 1.16.0
  - federation: 1.16.0
  - files: 1.21.1
  - files_external: 1.18.0
  - files_pdfviewer: 2.7.0
  - files_rightclick: 1.5.0
  - files_sharing: 1.18.0
  - files_trashbin: 1.16.0
  - files_versions: 1.19.1
  - firstrunwizard: 2.15.0
  - keeweb: 0.6.13
  - logreader: 2.11.0
  - lookup_server_connector: 1.14.0
  - mail: 3.4.0
  - money: 0.20.0
  - music: 1.8.4
  - nextcloud_announcements: 1.15.0
  - notes: 4.8.1
  - notifications: 2.14.0
  - oauth2: 1.14.1
  - password_policy: 1.16.0
  - photos: 2.2.0
  - privacy: 1.10.0
  - provisioning_api: 1.16.0
  - recommendations: 1.5.0
  - related_resources: 1.1.0
  - richdocuments: 8.0.4
  - serverinfo: 1.16.0
  - settings: 1.8.0
  - sharebymail: 1.16.0
  - spreed: 16.0.5
  - support: 1.9.0
  - survey_client: 1.14.0
  - systemtags: 1.16.0
  - text: 3.7.2
  - theming: 2.1.1
  - twofactor_backupcodes: 1.15.0
  - updatenotification: 1.16.0
  - user_status: 1.6.0
  - viewer: 1.10.0
  - weather_status: 1.6.0
  - workflowengine: 2.8.0
Disabled:
  - encryption: 2.14.0
  - suspicious_login: 4.4.0
  - twofactor_totp: 8.0.0
  - user_ldap: 1.16.0

Nextcloud Signing status

No errors have been found.

Nextcloud Logs

{"reqId":"MlU98CBQ7drtR711m2Iq","level":3,"time":"2023-09-18T19:30:31+00:00","remoteAddr":"213.xxx.xxx.xxx","user":"xxxxx","app":"no app in context","method":"PUT","url":"/ocs/v2.php/apps/weather_status/api/v1/location","message":"OCA\\WeatherStatus\\Service\\WeatherStatusService::searchForAddress(): Return value must be of type array, null returned in file '/home/my.domain.uk/public_html/apps/weather_status/lib/Service/WeatherStatusService.php' line 322","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/117.0","version":"26.0.1.1","exception":{"Exception":"Exception","Message":"OCA\\WeatherStatus\\Service\\WeatherStatusService::searchForAddress(): Return value must be of type array, null returned in file '/home/my.domain.uk/public_html/apps/weather_status/lib/Service/WeatherStatusService.php' line 322","Code":0,"Trace":[{"file":"/home/my.domain.uk/public_html/lib/private/AppFramework/App.php","line":183,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/home/my.domain.uk/public_html/lib/private/Route/Router.php","line":315,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/home/my.domain.uk/public_html/ocs/v1.php","line":64,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/home/my.domain.uk/public_html/ocs/v2.php","line":23,"args":["/home/my.domain.uk/public_html/ocs/v1.php"],"function":"require_once"}],"File":"/home/my.domain.uk/public_html/lib/private/AppFramework/Http/Dispatcher.php","Line":169,"Previous":{"Exception":"TypeError","Message":"OCA\\WeatherStatus\\Service\\WeatherStatusService::searchForAddress(): Return value must be of type array, null returned","Code":0,"Trace":[{"file":"/home/my.domain.uk/public_html/apps/weather_status/lib/Service/WeatherStatusService.php","line":284,"function":"searchForAddress","class":"OCA\\WeatherStatus\\Service\\WeatherStatusService","type":"->"},{"file":"/home/my.domain.uk/public_html/apps/weather_status/lib/Service/WeatherStatusService.php","line":196,"function":"setAddress","class":"OCA\\WeatherStatus\\Service\\WeatherStatusService","type":"->"},{"file":"/home/my.domain.uk/public_html/apps/weather_status/lib/Controller/WeatherStatusController.php","line":94,"function":"setLocation","class":"OCA\\WeatherStatus\\Service\\WeatherStatusService","type":"->"},{"file":"/home/my.domain.uk/public_html/lib/private/AppFramework/Http/Dispatcher.php","line":230,"function":"setLocation","class":"OCA\\WeatherStatus\\Controller\\WeatherStatusController","type":"->"},{"file":"/home/my.domain.uk/public_html/lib/private/AppFramework/Http/Dispatcher.php","line":137,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/home/my.domain.uk/public_html/lib/private/AppFramework/App.php","line":183,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/home/my.domain.uk/public_html/lib/private/Route/Router.php","line":315,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/home/my.domain.uk/public_html/ocs/v1.php","line":64,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/home/my.domain.uk/public_html/ocs/v2.php","line":23,"args":["/home/my.domain.uk/public_html/ocs/v1.php"],"function":"require_once"}],"File":"/home/my.domain.uk/public_html/apps/weather_status/lib/Service/WeatherStatusService.php","Line":322},"CustomMessage":"--"},"id":"650b01724ccb8"}

{"reqId":"MlU98CBQ7drtR711m2Iq","level":3,"time":"2023-09-18T19:30:31+00:00","remoteAddr":"213.xxx.xxx.xxx","user":"xxxxx","app":"PHP","method":"PUT","url":"/ocs/v2.php/apps/weather_status/api/v1/location","message":"Undefined array key 0 at /home/my.domain.uk/public_html/apps/weather_status/lib/Service/WeatherStatusService.php#322","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/117.0","version":"26.0.1.1","data":{"app":"PHP"},"id":"650b01724ccfb"}

{"reqId":"MlU98CBQ7drtR711m2Iq","level":2,"time":"2023-09-18T19:30:31+00:00","remoteAddr":"213.xxx.xxx.xxx","user":"xxxxx","app":"weather_status","method":"PUT","url":"/ocs/v2.php/apps/weather_status/api/v1/location","message":"https://nominatim.openstreetmap.org/search/Horton, Devizes, UKAPI error : GuzzleHttp\\Exception\\ClientException: Client error: `GET https://nominatim.openstreetmap.org/search/rton,%20Devizes,%20UK?format=json&addressdetails=1&extratags=1&namedetails=1&limit=1` resulted in a `404 Not Found` response:\n<html>\n<head>\n<title>File Not Found</title>\n</head>\n<body>\n<h1>File not found: API no longer accessible via this URL</h1 (truncated...)\n in /home/my.domain.uk/public_html/3rdparty/guzzlehttp/guzzle/src/Exception/RequestException.php:113\nStack trace:\n#0 /home/my.domain.uk/public_html/3rdparty/guzzlehttp/guzzle/src/Middleware.php(69): GuzzleHttp\\Exception\\RequestException::create()\n#1 /home/my.domain.uk/public_html/3rdparty/guzzlehttp/promises/src/Promise.php(204): GuzzleHttp\\Middleware::GuzzleHttp\\{closure}()\n#2 /home/my.domain.uk/public_html/3rdparty/guzzlehttp/promises/src/Promise.php(153): GuzzleHttp\\Promise\\Promise::callHandler()\n#3 /home/my.domain.uk/public_html/3rdparty/guzzlehttp/promises/src/TaskQueue.php(48): GuzzleHttp\\Promise\\Promise::GuzzleHttp\\Promise\\{closure}()\n#4 /home/my.domain.uk/public_html/3rdparty/guzzlehttp/promises/src/Promise.php(248): GuzzleHttp\\Promise\\TaskQueue->run()\n#5 /home/my.domain.uk/public_html/3rdparty/guzzlehttp/promises/src/Promise.php(224): GuzzleHttp\\Promise\\Promise->invokeWaitFn()\n#6 /home/my.domain.uk/public_html/3rdparty/guzzlehttp/promises/src/Promise.php(269): GuzzleHttp\\Promise\\Promise->waitIfPending()\n#7 /home/my.domain.uk/public_html/3rdparty/guzzlehttp/promises/src/Promise.php(226): GuzzleHttp\\Promise\\Promise->invokeWaitList()\n#8 /home/my.domain.uk/public_html/3rdparty/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\\Promise\\Promise->waitIfPending()\n#9 /home/my.domain.uk/public_html/3rdparty/guzzlehttp/guzzle/src/Client.php(187): GuzzleHttp\\Promise\\Promise->wait()\n#10 /home/my.domain.uk/public_html/lib/private/Http/Client/Client.php(226): GuzzleHttp\\Client->request()\n#11 /home/my.domain.uk/public_html/apps/weather_status/lib/Service/WeatherStatusService.php(415): OC\\Http\\Client\\Client->get()\n#12 /home/my.domain.uk/public_html/apps/weather_status/lib/Service/WeatherStatusService.php(320): OCA\\WeatherStatus\\Service\\WeatherStatusService->requestJSON()\n#13 /home/my.domain.uk/public_html/apps/weather_status/lib/Service/WeatherStatusService.php(284): OCA\\WeatherStatus\\Service\\WeatherStatusService->searchForAddress()\n#14 /home/my.domain.uk/public_html/apps/weather_status/lib/Service/WeatherStatusService.php(196): OCA\\WeatherStatus\\Service\\WeatherStatusService->setAddress()\n#15 /home/my.domain.uk/public_html/apps/weather_status/lib/Controller/WeatherStatusController.php(94): OCA\\WeatherStatus\\Service\\WeatherStatusService->setLocation()\n#16 /home/my.domain.uk/public_html/lib/private/AppFramework/Http/Dispatcher.php(230): OCA\\WeatherStatus\\Controller\\WeatherStatusController->setLocation()\n#17 /home/my.domain.uk/public_html/lib/private/AppFramework/Http/Dispatcher.php(137): OC\\AppFramework\\Http\\Dispatcher->executeController()\n#18 /home/my.domain.uk/public_html/lib/private/AppFramework/App.php(183): OC\\AppFramework\\Http\\Dispatcher->dispatch()\n#19 /home/my.domain.uk/public_html/lib/private/Route/Router.php(315): OC\\AppFramework\\App::main()\n#20 /home/my.domain.uk/public_html/ocs/v1.php(64): OC\\Route\\Router->match()\n#21 /home/my.domain.uk/public_html/ocs/v2.php(23): require_once('...')\n#22 {main}","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/117.0","version":"26.0.1.1","data":{"app":"weather_status"},"id":"650b01724cece"}

Additional info

The api endpoint is incorrect for the openstreet map API.

I have made amendments to the /apps/weather_status/lib/Service/WeatherStatusService.php file to correct the behaviour.

WeatherStatusService.txt

@ds4a ds4a added 0. Needs triage Pending check for reproducibility or if it fits our roadmap bug labels Sep 20, 2023
@Baton4986
Copy link

Same on Nextcloud 25.0.9-0 (latest official App on Univention Corporate Server)

@ds4a
Copy link
Author

ds4a commented Sep 24, 2023

I've now polished my original quick fix for this issue, the updated temporary fix file is located at:
[https://raw.githubusercontent.com/ds4a/NC/main/WeatherStatusService.php]

@joshtrichards
Copy link
Member

Hi @ds4a - I can't reproduce this behavior in NC26 (with the same weather_status version as you) nor in NC27.

The way we build the URL and pass the parameters already passes the q= by default:

$params = [
'q' => $address,
'format' => 'json',
'addressdetails' => '1',
'extratags' => '1',
'namedetails' => '1',

if (count($params) > 0) {
$paramsContent = http_build_query($params);
$reqUrl = $url . '?' . $paramsContent;

https://nominatim.openstreetmap.org/search/rton,%20Devizes,%20UK?format=json&addressdetails=1&extratags=1&namedetails=1&limit=1

That URL in your logs looks really strange as it is missing the q= but that doesn't happen for me. Is rton part of your search string? i.e. In this example is the address you're entering in the box "rton, devizes, UK"?

Can you re-test with an unmodified version of the weather_status app?

https://github.com/nextcloud/server/blob/stable26/apps/weather_status/lib/Service/WeatherStatusService.php

@nextcloud-command

This comment was marked as resolved.

@nextcloud-command nextcloud-command added the stale Ticket or PR with no recent activity label Jan 24, 2024
@ds4a
Copy link
Author

ds4a commented Jan 24, 2024

Hi @joshtrichards,

I've retried with the unmodified version that was linked to and it's does work, although something doesn't quite seem right with whats displayed in the dashboard.

The rton was probably a typo for Horton, Devizes, UK. At the time I'd tried lots of locations and all produced the same error, here's some others from my logs at the time:

GET https://nominatim.openstreetmap.org/search/Bristol?format=json&addressdetails=1&extratags=1&namedetails=1&limit=1` resulted in a 404 Not Found

GET https://nominatim.openstreetmap.org/search/Devizes?format=json&addressdetails=1&extratags=1&namedetails=1&limit=1` resulted in a 404 Not Found

GET https://nominatim.openstreetmap.org/search/Easton,%20Bristol,%20United%20Kingdom?format=json&addressdetails=1&extratags=1&namedetails=1&limit=1` resulted in a 404 Not Found

All with the endpoint response of: response:\n\n\n<title>File Not Found</title>\n\n\n

File not found: API no longer accessible via this URL</h1 (truncated...)\n

However all appears to work as expected in my current NC 28.0.1

@ds4a
Copy link
Author

ds4a commented Jan 24, 2024

Hi @joshtrichards,

I pulled up a backup of the WeatherStatusService.php which I had as part of my installation, which contained some subtle differences to the file you referenced:

My installed version (note the trailing slash after search/) and the . $address:
also the exclusion of the q' => $address, from the params array.

	/**
	 * Ask nominatim information about an unformatted address
	 *
	 * @param string Unformatted address
	 * @return array Full Nominatim result for the given address
	 */
	private function searchForAddress(string $address): array {
		$params = [
			'format' => 'json',
			'addressdetails' => '1',
			'extratags' => '1',
			'namedetails' => '1',
			'limit' => '1',
		];
		$url = 'https://nominatim.openstreetmap.org/search/' . $address;
		$results = $this->requestJSON($url, $params);
		if (count($results) > 0) {
			return $results[0];
		}
		return ['error' => $this->l10n->t('No result.')];
	}
The linked version:
		/**
	 * Ask nominatim information about an unformatted address
	 *
	 * @param string Unformatted address
	 * @return array Full Nominatim result for the given address
	 */
	private function searchForAddress(string $address): array {
		$params = [
			'q' => $address,
			'format' => 'json',
			'addressdetails' => '1',
			'extratags' => '1',
			'namedetails' => '1',
			'limit' => '1',
		];
		$url = 'https://nominatim.openstreetmap.org/search';
		$results = $this->requestJSON($url, $params);
		if (count($results) > 0) {
			return $results[0];
		}
		return ['error' => $this->l10n->t('No result.')];
	}

@ds4a
Copy link
Author

ds4a commented Jan 24, 2024

Does @ramon-kramer have their original file? Does it contain the same code between lines 305 and 325?

@joshtrichards joshtrichards removed needs info stale Ticket or PR with no recent activity labels Jan 24, 2024
@joshtrichards
Copy link
Member

joshtrichards commented Aug 18, 2024

I think you just caught this just before the fix was released: #38665 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 26-feedback bug feature: dashboard
Projects
None yet
Development

No branches or pull requests

5 participants