Add FCM device id to a variable in python using get_clipboard_text()

Hi,

There is my scenario:

I have a button in a debug menu where I copy into my clipboard an FCM device id and then I use it the following way:

deviceToken = self.driver.get_clipboard_text()

afterwards, I use this variable in my ‘body’ like:

        body = {
            "to": deviceToken,
            "notification": {
                "body": "Welcome to blabla",
                "title": "Bla bla trully loves you, did you know that?",
                "priority": "high"
            }

But unfortunately, I get the following response:

200
{'multicast_id': 3155000136518118544, 'success': 0, 'failure': 1, 'canonical_ids': 0, 'results': [{'error': 'InvalidRegistration'}]} 

I dont think it’s an Appium issue, but maybe the way I use the get_clipboard_text into my variable, because if I put the FCM id manually like here:

 deviceToken = 'dI2jZgvnTkODJ9-0WHkRLT:APA91bENeuYA9TqabkiVCLD8toZ1n85KlWHWHmUsgs_9ixHWiDH9uFtZYTW1PVTN8eGs9cU8lc2j2FlwINdfUdyd3PxBoT3DpcZ0iRZoOaz7Ji_hD0yjnHlwx4urRei4fguwF5sAx1Pj'

It will work without any kind of issue.

Any thoughts on how exactly should I insert the id into the variable? Maybe to add some commas, idk…

Thanks!

Any ideas? Maybe a decoding issue?

If I use:

deviceToken = self.driver.get_clipboard(ClipboardContentType.PLAINTEXT)

I will get the following error:

ERROR: test_firebaseTest (__main__.firebaseTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "firebaseTest.py", line 78, in test_firebaseTest
    response = requests.post("https://fcm.googleapis.com/fcm/send", headers=headers, data=json.dumps(body))
  File "/usr/local/Cellar/[email protected]/3.8.3_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/local/Cellar/[email protected]/3.8.3_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/Cellar/[email protected]/3.8.3_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/Cellar/[email protected]/3.8.3_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable