Coder Social home page Coder Social logo

Comments (14)

1letter avatar 1letter commented on July 20, 2024 1

Is anybody else having the same issue? Am I using plone.restapi wrong?

Yes, today the same happend here.

from plone.restapi.

1letter avatar 1letter commented on July 20, 2024 1

@ale-rt
I can confirm, that the patch helps. Thanks.

from plone.restapi.

1letter avatar 1letter commented on July 20, 2024 1

@ale-rt if you need help, let me know

from plone.restapi.

1letter avatar 1letter commented on July 20, 2024 1

@ale-rt with your patch in zope the following test doesn't fail in my Project :

def test_querystringsearch_metadata_fields_get_request_as_anon(self):
    from urllib.parse import quote
    import json

    self.api_session = RelativeSession(self.portal_url, test=self)
    self.api_session.headers.update({"Accept": "application/json"})
    self.api_session.headers.update({"Content-Type": "application/json"})

    data = {
        "query": [
            {
                "i": "portal_type",
                "o": "plone.app.querystring.operation.selection.is",
                "v": ["News Item"],
            }
        ],
        "metadata_fields": ["image_scales", "getIcon"],
    }
    response = self.api_session.get(
        "/@querystring-search",
        proxies=self._proxies,
        params={"query": quote(json.dumps(data))},
    )

    self.assertEqual(response.status_code, 200)
    self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
    self.assertEqual(
        response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
    )

Note: The Project use the master branch of plone.restapi with a fix for the GET Request in Endpoint @querystring-search, but it'S not related to these issue

Update: I will check, what happens when i removing the content-type header

from plone.restapi.

ale-rt avatar ale-rt commented on July 20, 2024 1

I am closing this one because I think the details are now clear: you shall not send a Content-Type header on a GET request :)
I opened a PR for pat-calendar: Patternslib/Patterns#1157

from plone.restapi.

davisagli avatar davisagli commented on July 20, 2024

@ale-rt The thing I don't understand about this is: why is Zope throwing an error about having both a querystring and a body when you didn't send a body?

from plone.restapi.

ale-rt avatar ale-rt commented on July 20, 2024

I did not get it as well and did not dig into the issue enough to grok it :)

I am temporarily using this branch to make the site work: zopefoundation/Zope#1117

from plone.restapi.

1letter avatar 1letter commented on July 20, 2024

@ale-rt i will check the workaround tomorrow. I have upgraded today a Plone Site from 6.0.0.3 to 6.0.3 and see the error in a custom Rest-API endpoint call. It's a simple GET Request with a parameter.

from plone.restapi.

ale-rt avatar ale-rt commented on July 20, 2024

I will try to dig deeper and make the patch merged.

from plone.restapi.

ale-rt avatar ale-rt commented on July 20, 2024

I dug in to the issue and came up with a different patch that I think is more comprehensive.

zopefoundation/Zope#1117

The problem is that the current code does not actually check there is a body in the request.

from plone.restapi.

ale-rt avatar ale-rt commented on July 20, 2024

@1letter did you by chance has the issue while using pat-calendar?
It seems it is mistakenly adding the Content-Type header here:
https://github.com/Patternslib/Patterns/blob/7e391d33ed84bf8461d7c0c04f80ec157c23e549/src/pat/calendar/calendar.js#L311-L318
I will probably transfer this issue there.

from plone.restapi.

1letter avatar 1letter commented on July 20, 2024

@ale-rt no, it was a custom rest-api endpoint call. It's a simple GET Request with a parameter. but the structure is similar like you linked.

from plone.restapi.

ale-rt avatar ale-rt commented on July 20, 2024

As you noted, the reason why your test fails should be this line:

self.api_session.headers.update({"Content-Type": "application/json"})

You should not need it (see zopefoundation/Zope#1117 (review)).

from plone.restapi.

1letter avatar 1letter commented on July 20, 2024

@ale-rt You were correct, the useless header with an empty body in the GET request was the problem.

from plone.restapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.