gicait / geoserver-rest

Python library for management of geospatial data in GeoServer.
https://geoserver-rest.readthedocs.io
MIT License
197 stars 79 forks source link

get_status() doesn't return json #86

Closed gtitov closed 1 year ago

gtitov commented 2 years ago

Hey! Thanks for a great product!

Description

geoserver-rest==2.3.4
requests==2.28.1

Geoserver API doesn't return a JSON-response to a request in the get_status() method of the Geoserver class. So return of the method doesn't produce a valid output. I'm not sure if it is only my specific problem because the get_system_status() method works just fine with a similar request.

Code to reproduce

from geo.Geoserver import Geoserver
geo = Geoserver('http://127.0.0.1:9090', username='admin', password='geoserver')
status = geo.get_status()
system_status = geo.get_system_status()
print(status)
print(system_status)

Output (truncated)

('get_status error: ', JSONDecodeError('Expecting value: line 1 column 1 (char 0)'))
{'metrics': {'metric': [{'available': False, 'description': 'Operating system', 'name': 'OPERATING_SYSTEM', 'unit': '', 'category': 'SYSTEM', 'identifier': 'OPERATING_SYSTEM', 'priority': 1, 'value': 'NOT AVAILABLE'}, ...

Possible solution

Add a header to ensure json return.

def get_status(self):
        """
        Returns the status of the geoserver. It shows the status details of all installed and configured modules.
        """
        try:
            url = "{}/rest/about/status.json".format(self.service_url)
            r = requests.get(url, auth=(self.username, self.password), headers={"Accept": "application/json"})
            return r.json()
Kilometerfresserin commented 1 year ago

Hi, thanks for the cool package.

I encountered the same problem @gtitov mentioned, but with the create_coveragestore function.

requests==2.28.1
geoserver-rest==2.4.0

I'd be happy to help fixing, but I've never contributed on any github project, so I'm not quite sure how to start.

iamtekson commented 1 year ago

Hi @Kilometerfresserin and @gtitov, could you please use the latest version v2.4.0. I think this issue was solved with the latest release.

Kilometerfresserin commented 1 year ago

Hi @iamtekson. Thanks for the quick reply.

I have double-checked my version and I'm sure I'm already running on 2.4.0.

I believe it has been solved for the get_status method that @gtitov mentioned (at least that one works fine for me), but it still occurs with create_coveragestore method.

Again, I'd be happy to provide the bugfix myself, if that is okay with you.

iamtekson commented 1 year ago

Hi @Kilometerfresserin, Please go ahead and fix the bug. I will merge it. But before doing that, could you please provide the error message on this issue or create new issue?

JamesSample commented 1 year ago

I've just encountered the same problem with geoserver-rest==2.4.0:

import os
from geo.Geoserver import Geoserver
from config import SETTINGS

geo = Geoserver(
    "https://my/geoserver/url",
    username=SETTINGS.GEOSERVER_USER,
    password=SETTINGS.GEOSERVER_PASSWORD,
)

fpath = r"/path/to/my_file.tif"
fname = os.path.basename(fpath)
layer_name = os.path.splitext(fname)[0]
status = geo.create_coveragestore(
    layer_name=layer_name, path=fpath, workspace="my_workspace"
)
print(status)

Gives the following error:

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

If I downgrade to version 2.3.4, everything works OK.

iamtekson commented 1 year ago

Thank you for reporting it. I will have a look and fix the things soon. After that, we can close this issue.

Kilometerfresserin commented 1 year ago

Hi @Kilometerfresserin, Please go ahead and fix the bug. I will merge it. But before doing that, could you please provide the error message on this issue or create new issue?

Hi @iamtekson I've checked out main branch, branched from it it and fixed the issue, but I seem to lack permission to publish the new branch:

jw@MacBook-Pro geoserver-rest % git push -u origin issue_86_missing_application_json
remote: Permission to gicait/geoserver-rest.git denied to Kilometerfresserin.
fatal: unable to access 'https://github.com/gicait/geoserver-rest.git/': The requested URL returned error: 403

Maybe I haven't understood github (I've only worked with self-hosted gitlab instances so far) - could someone please explain how to do this correctly around here?

JamesSample commented 1 year ago

@Kilometerfresserin It is likely that only "core" project contributors have permissions to create and publish branches on the original repository. Instead, you should first "fork" the repository, which creates a copy of the original linked to your own GitHub profile. You can then create a branch on your fork, make changes and commit them to your branch. Finally, make a pull request from the original repository by comparing with changes on your branch. See e.g. here and here.

Good luck!