Cherrypy App Server to receive PUSH notifications from Google Drive API

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Cherrypy App Server to receive PUSH notifications from Google Drive API

Alex S.
Hello guys, I'm stuck trying to sync Google drive PUSH notifications with my cherrypy App Server.

Here is my Cherrypy Server which functions normal when it reives JSON format
Response 200

#!/usr/bin/python3
 
import cherrypy
import json
import ws_proc
 
PORT = 9000
 
p = ws_proc.Ws_proc()
 
def cors():
    if cherrypy.request.method == 'OPTIONS':
        # preflign request  
        # see http://www.w3.org/TR/cors/#cross-origin-request-with-preflight-0
        cherrypy.response.headers['Access-Control-Allow-Methods'] = 'POST'
        cherrypy.response.headers['Access-Control-Allow-Headers'] = 'content-type'
        cherrypy.response.headers['Access-Control-Allow-Origin']  = '*'
        # tell CherryPy no avoid normal handler
        return True
    else:
        cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'
 
cherrypy.tools.cors = cherrypy._cptools.HandlerTool(cors)
 
@cherrypy.expose
class Greetings(object):
    def GET(self):
        return 'Welcome to CloudBackOffice.team Webservice'
 
@cherrypy.expose
@cherrypy.config(**{'tools.cors.on': True})
@cherrypy.tools.json_out()
@cherrypy.tools.json_in()
class POSTHandlerWebService(object):
    def POST(self):
        data = cherrypy.request.json
        return data
 
 
 
if __name__ == '__main__':
 
    # Global config
    cherrypy.config.update({'server.socket_port': PORT,
                            'server.socket_host': '127.0.0.1'})
 
 
    # Web Service config
    conf = {
        '/': {
            'response.timeout': 6000,
            'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
            'tools.sessions.on': True
            }   
          }
 
    root = Greetings()
    root.send = POSTHandlerWebService()
    cherrypy.quickstart(root, config=conf)


The problem is when attempting to sync with the PUSH notifications it sends a POST message with this format:

POST https://mydomain.com/notifications // Your receiving URL. X-Goog-Channel-ID: channel-ID-value X-Goog-Channel-Token: channel-token-value X-Goog-Channel-Expiration: expiration-date-and-time // In human-readable format; present only if channel expires. X-Goog-Resource-ID: identifier-for-the-watched-resource X-Goog-Resource-URI: version-specific-URI-of-the-watched-resource X-Goog-Resource-State: sync X-Goog-Message-Number: 1

Response 415

Somebody can help on clarify why it isn't working.

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/e4c9f8fe-1ed3-4b71-90fc-4b6a69b1b8bfn%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Cherrypy App Server to receive PUSH notifications from Google Drive API

Sviatoslav Sydorenko (@webknjaz)
Hey Alex,

пн, 1 бер. 2021 о 17:58 Alex S. <[hidden email]> пише:

> POST https://mydomain.com/notifications // Your receiving URL.
> X-Goog-Channel-ID: channel-ID-value X-Goog-Channel-Token:
> channel-token-value X-Goog-Channel-Expiration:
> expiration-date-and-time // In human-readable format; present
> only if channel expires. X-Goog-Resource-ID:
> identifier-for-the-watched-resource X-Goog-Resource-URI:
> version-specific-URI-of-the-watched-resource
> X-Goog-Resource-State: sync X-Goog-Message-Number: 1
>
> Response 415
>
> Somebody can help on clarify why it isn't working.

You need to record the network traffic of that HTTP request to be
able to figure out what's going on.
But the HTTP response of 415 Unsupported Media Type[1] likely
means that the Content-Type in their request is not `application/json`[2].

By the way, have you tried cherrypy-cors[3] for the CORS setup?

[1]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/415
[2]: https://github.com/cherrypy/cherrypy/blob/98929b5/cherrypy/lib/jsontools.py#L16
[3]: https://stackoverflow.com/a/57653463/595220


--
Cheers,
Sviatoslav.

---
https://useplaintext.email/
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments
---

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/CAFYONRCKj5vK6C0dCPyc6L4uSVsqYffy-tDMTkTxuZ9BK5dbRw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Cherrypy App Server to receive PUSH notifications from Google Drive API

Alex S.
Hi Sviatoslav,

This is the answer from App server when sending the request as the sync message from Google Drive API using a testing tool

<Response [415]>
{'Server': 'nginx/1.18.0', 'Date': 'Mon, 01 Mar 2021 16:47:10 GMT', 'Content-Type': 'text/html;charset=utf-8', 'Content-Length': '1734', 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=60', 'Allow': 'POST', 'Set-Cookie': 'session_id=0a04df85ab66c695d3213fc15df91d1fd3b7ce5c; expires=Mon, 01 Mar 2021 17:47:10 GMT; Max-Age=3600; Path=/'}

Sure I'm expecting an application/json request but for google drive push notifications it sends both application/json and text/html

I tested using cherrypy-cors but something is misconfigured.

I'm really stuck at this point, after a week of configuring this. I willtry again with the cherrypy-cors tool.

A. Senges
--
Just a human among others in the Uncanny valley.


On Mon, Mar 1, 2021 at 1:21 PM Sviatoslav Sydorenko <[hidden email]> wrote:
Hey Alex,

пн, 1 бер. 2021 о 17:58 Alex S. <[hidden email]> пише:
> POST https://mydomain.com/notifications // Your receiving URL.
> X-Goog-Channel-ID: channel-ID-value X-Goog-Channel-Token:
> channel-token-value X-Goog-Channel-Expiration:
> expiration-date-and-time // In human-readable format; present
> only if channel expires. X-Goog-Resource-ID:
> identifier-for-the-watched-resource X-Goog-Resource-URI:
> version-specific-URI-of-the-watched-resource
> X-Goog-Resource-State: sync X-Goog-Message-Number: 1
>
> Response 415
>
> Somebody can help on clarify why it isn't working.

You need to record the network traffic of that HTTP request to be
able to figure out what's going on.
But the HTTP response of 415 Unsupported Media Type[1] likely
means that the Content-Type in their request is not `application/json`[2].

By the way, have you tried cherrypy-cors[3] for the CORS setup?

[1]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/415
[2]: https://github.com/cherrypy/cherrypy/blob/98929b5/cherrypy/lib/jsontools.py#L16
[3]: https://stackoverflow.com/a/57653463/595220


--
Cheers,
Sviatoslav.

---
https://useplaintext.email/
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments
---

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/CAFYONRCKj5vK6C0dCPyc6L4uSVsqYffy-tDMTkTxuZ9BK5dbRw%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/CA%2B7mbXuJbtiX8QX9_05r1W8HRU5t8B20DyJYa2DOmo8H_N%3D%3DnA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Cherrypy App Server to receive PUSH notifications from Google Drive API

Tim Roberts
In reply to this post by Alex S.
Alex S. wrote:
> Hello guys, I'm stuck trying to sync Google drive PUSH notifications
> with my cherrypy App Server.
>
> Here is my Cherrypy Server which functions normal when it reives JSON
> format
> ...
> The problem is when attempting to sync with the PUSH notifications it
> sends a POST message with this format:

I'm confused.  Are you saying YOUR server receives that POST request,
and responds with a 415?

The notification sync messages don't have any input or output. There is
no JSON for you to read, and you're not expected to send anything back.

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.


--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/1de3b87a-aa05-ee34-a0cf-ae86afb9aa50%40probo.com.

smime.p7s (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Cherrypy App Server to receive PUSH notifications from Google Drive API

Sviatoslav Sydorenko (@webknjaz)
In reply to this post by Alex S.
пн, 1 бер. 2021 о 18:45 Alex S. <[hidden email]> пише:
> This is the answer from App server when sending the request as the sync message from Google Drive API using a testing tool
>
> <Response [415]>
> {'Server': 'nginx/1.18.0', 'Date': 'Mon, 01 Mar 2021 16:47:10 GMT', 'Content-Type': 'text/html;charset=utf-8', 'Content-Length': '1734', 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=60', 'Allow': 'POST', 'Set-Cookie': 'session_id=0a04df85ab66c695d3213fc15df91d1fd3b7ce5c; expires=Mon, 01 Mar 2021 17:47:10 GMT; Max-Age=3600; Path=/'}
>
> Sure I'm expecting an application/json request but for google drive push notifications it sends both application/json and text/html
>

I don't think the response is important. We've already determined that
`json_in` causes HTTP 415 because the incoming request does not
use proper `Content-Type` headers. You can replace the allowed type
values by changing the `content_type` setting of `json_in`. But in the
light of what Tim wrote above, it sounds that you shouldn't expect
JSON at all.

I haven't used this service but according to
https://developers.google.com/drive/api/v3/push#examples,
the body can be missing. You should probably try just accepting
raw requests with an undecorated handler, log that and act
accordingly.


--
Cheers,
Sviatoslav.

---
https://useplaintext.email/
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments
---

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/CAFYONRBcWv_3whAZkfxTHHEyitqa%3DEDicr0Yz-SgwtfubgLjEg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Cherrypy App Server to receive PUSH notifications from Google Drive API

Alex S.
Well I was expecting JSON because the docs explains that after created the channel with the Drive API it returns a message with this format:

POST https://mydomain.com/notifications // Your receiving URL.
X-Goog-Channel-ID: channel-ID-value
X-Goog-Channel-Token: channel-token-value
X-Goog-Channel-Expiration: expiration-date-and-time // In human-readable format; present only if channel expires.
X-Goog-Resource-ID: identifier-for-the-watched-resource
X-Goog-Resource-URI: version-specific-URI-of-the-watched-resource
X-Goog-Resource-State: sync
X-Goog-Message-Number: 1


But when sending PUSH notifiactions the format is JSON with or without body

POST https://mydomain.com/notifications // Your receiving URL. Content-Type: application/json; utf-8 Content-Length: 118 X-Goog-Channel-ID: 8bd90be9-3a58-3122-ab43-9823188a5b43 X-Goog-Channel-Token: 245t1234tt83trrt333 X-Goog-Channel-Expiration: Tue, 19 Nov 2013 01:13:52 GMT X-Goog-Resource-ID: ret987df98743md8g X-Goog-Resource-URI: <a href="https://www.googleapis.com/drive/v3/changes X-Goog-Resource-State">https://www.googleapis.com/drive/v3/changes X-Goog-Resource-State: changed X-Goog-Message-Number: 23 { "kind": "drive#changes" }

The first message is for sync purpose but I dont know how to handle both formats in the same endpoint.

Please refer to https://developers.google.com/drive/api/v3/push


A. Senges
--
Just a human among others in the Uncanny valley.


On Mon, Mar 1, 2021 at 1:56 PM Sviatoslav Sydorenko <[hidden email]> wrote:
пн, 1 бер. 2021 о 18:45 Alex S. <[hidden email]> пише:
> This is the answer from App server when sending the request as the sync message from Google Drive API using a testing tool
>
> <Response [415]>
> {'Server': 'nginx/1.18.0', 'Date': 'Mon, 01 Mar 2021 16:47:10 GMT', 'Content-Type': 'text/html;charset=utf-8', 'Content-Length': '1734', 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=60', 'Allow': 'POST', 'Set-Cookie': 'session_id=0a04df85ab66c695d3213fc15df91d1fd3b7ce5c; expires=Mon, 01 Mar 2021 17:47:10 GMT; Max-Age=3600; Path=/'}
>
> Sure I'm expecting an application/json request but for google drive push notifications it sends both application/json and text/html
>

I don't think the response is important. We've already determined that
`json_in` causes HTTP 415 because the incoming request does not
use proper `Content-Type` headers. You can replace the allowed type
values by changing the `content_type` setting of `json_in`. But in the
light of what Tim wrote above, it sounds that you shouldn't expect
JSON at all.

I haven't used this service but according to
https://developers.google.com/drive/api/v3/push#examples,
the body can be missing. You should probably try just accepting
raw requests with an undecorated handler, log that and act
accordingly.


--
Cheers,
Sviatoslav.

---
https://useplaintext.email/
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments
---

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/CAFYONRBcWv_3whAZkfxTHHEyitqa%3DEDicr0Yz-SgwtfubgLjEg%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/CA%2B7mbXtrRBakGjyRkw8sS%3DfziPO05KCiAURqbFRUzMVP_8GQUQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Cherrypy App Server to receive PUSH notifications from Google Drive API

Alex S.
Hey guys now responding 200

I attended your advice Tim and Sviatoslav.

So PUSH notifications aren't JSON as I was expecting. 

127.0.0.1 - - [01/Mar/2021:16:56:52] "POST /send HTTP/1.1" 200 684 "" "python-requests/2.24.0"
127.0.0.1 - - [01/Mar/2021:16:58:18] "POST /send HTTP/1.1" 200 861 "" "APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html)"

The first one is from my testing tool and the second one from google I guess is the sync message.

Thanks a lot!

But for now I open and edit a file in my drive but nothing arrives to notify me. What am I doing wrong?

A. Senges
--
Just a human among others in the Uncanny valley.


On Mon, Mar 1, 2021 at 5:34 PM Alex S. <[hidden email]> wrote:
Well I was expecting JSON because the docs explains that after created the channel with the Drive API it returns a message with this format:

POST https://mydomain.com/notifications // Your receiving URL.
X-Goog-Channel-ID: channel-ID-value
X-Goog-Channel-Token: channel-token-value
X-Goog-Channel-Expiration: expiration-date-and-time // In human-readable format; present only if channel expires.
X-Goog-Resource-ID: identifier-for-the-watched-resource
X-Goog-Resource-URI: version-specific-URI-of-the-watched-resource
X-Goog-Resource-State: sync
X-Goog-Message-Number: 1


But when sending PUSH notifiactions the format is JSON with or without body

POST https://mydomain.com/notifications // Your receiving URL. Content-Type: application/json; utf-8 Content-Length: 118 X-Goog-Channel-ID: 8bd90be9-3a58-3122-ab43-9823188a5b43 X-Goog-Channel-Token: 245t1234tt83trrt333 X-Goog-Channel-Expiration: Tue, 19 Nov 2013 01:13:52 GMT X-Goog-Resource-ID: ret987df98743md8g X-Goog-Resource-URI: https://www.googleapis.com/drive/v3/changes X-Goog-Resource-State: changed X-Goog-Message-Number: 23 { "kind": "drive#changes" }

The first message is for sync purpose but I dont know how to handle both formats in the same endpoint.

Please refer to https://developers.google.com/drive/api/v3/push


A. Senges
--
Just a human among others in the Uncanny valley.


On Mon, Mar 1, 2021 at 1:56 PM Sviatoslav Sydorenko <[hidden email]> wrote:
пн, 1 бер. 2021 о 18:45 Alex S. <[hidden email]> пише:
> This is the answer from App server when sending the request as the sync message from Google Drive API using a testing tool
>
> <Response [415]>
> {'Server': 'nginx/1.18.0', 'Date': 'Mon, 01 Mar 2021 16:47:10 GMT', 'Content-Type': 'text/html;charset=utf-8', 'Content-Length': '1734', 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=60', 'Allow': 'POST', 'Set-Cookie': 'session_id=0a04df85ab66c695d3213fc15df91d1fd3b7ce5c; expires=Mon, 01 Mar 2021 17:47:10 GMT; Max-Age=3600; Path=/'}
>
> Sure I'm expecting an application/json request but for google drive push notifications it sends both application/json and text/html
>

I don't think the response is important. We've already determined that
`json_in` causes HTTP 415 because the incoming request does not
use proper `Content-Type` headers. You can replace the allowed type
values by changing the `content_type` setting of `json_in`. But in the
light of what Tim wrote above, it sounds that you shouldn't expect
JSON at all.

I haven't used this service but according to
https://developers.google.com/drive/api/v3/push#examples,
the body can be missing. You should probably try just accepting
raw requests with an undecorated handler, log that and act
accordingly.


--
Cheers,
Sviatoslav.

---
https://useplaintext.email/
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments
---

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/CAFYONRBcWv_3whAZkfxTHHEyitqa%3DEDicr0Yz-SgwtfubgLjEg%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/CA%2B7mbXsK9DHSJOwJgHRXnw6Sre6iVgkd1GycK8P0mVhYUveRXA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Cherrypy App Server to receive PUSH notifications from Google Drive API

Tim Roberts
Alex S. wrote:
>
> But for now I open and edit a file in my drive but nothing arrives to
> notify me. What am I doing wrong?

What you're doing wrong is expecting a notification.  The push
notifications are only for when a resource CHANGES.  Opening a file
doesn't change the resource.

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.


--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/3ff91478-51a0-67c3-f968-3271767d178e%40probo.com.

smime.p7s (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Cherrypy App Server to receive PUSH notifications from Google Drive API

Alex S.
Hello Tim, I've edited files, even delete files, but nothing arrives. I guess it's something about response 200  to indicate success to the drive api. But when returning an object response, I am having an encode error. I am still trying to synchronize.


A. Senges
--
Just a human among others in the Uncanny valley.


On Tue, Mar 2, 2021 at 1:09 PM Tim Roberts <[hidden email]> wrote:
Alex S. wrote:
>
> But for now I open and edit a file in my drive but nothing arrives to
> notify me. What am I doing wrong?

What you're doing wrong is expecting a notification.  The push
notifications are only for when a resource CHANGES.  Opening a file
doesn't change the resource.

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.


--
You received this message because you are subscribed to a topic in the Google Groups "cherrypy-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cherrypy-users/aTXXTDLYVUE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/3ff91478-51a0-67c3-f968-3271767d178e%40probo.com.

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/CA%2B7mbXszJcD2R5G_iUrX40cJKR7pBmoV1Ys69oqp%3D22iVfqy%3Dg%40mail.gmail.com.