windkh / node-red-contrib-telegrambot

Telegram bot nodes for node-red.
Other
262 stars 116 forks source link

type photo: EFATAL: TypeError [ERR_INVALID_CHAR] #215

Closed OKDaG closed 2 years ago

OKDaG commented 2 years ago

Hi, i'm running nodered v2.0.6 with node-red-contrib-telegrambot v10.0.7 and wanted to send a photo with Telegram Sender but got this error:

msg.payload: object {"chatId":279600xxx,"type":"photo","content":"/tmp/cam.jpg","caption":"Hof"}

msg.string[349] Caught exception in sender node: Error: EFATAL: TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["getKeyByValue"] when processing message: {"_msgid":"e06280de37aaa560","payload":{"chatId":279600xxx,"type":"photo","content":"/tmp/cam.jpg","caption":"Hof","options":{"caption":"Hof","chat_id":279600xxx,"photo":null}},"topic":""}

Any hints?

windkh commented 2 years ago

Thanks for reporting. I have never seen this before. Is it reproducable? Can you send me the flow with an example photo via email?

OKDaG commented 2 years ago

[{"id":"96f77d076a52f9a7","type":"inject","z":"f6f2187d.f17ca8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":520,"wires":[["1b6e18b0c16520ba"]]},{"id":"1b6e18b0c16520ba","type":"http request","z":"f6f2187d.f17ca8","name":"","method":"GET","ret":"bin","paytoqs":"ignore","url":"https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg","tls":"","persist":false,"proxy":"","authType":"","x":370,"y":520,"wires":[["dd38153198a762ec","c018db46f8e21c08"]]},{"id":"dd38153198a762ec","type":"file","z":"f6f2187d.f17ca8","name":"","filename":"/tmp/test.jpg","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":570,"y":520,"wires":[["3bbe515a2e0f8c10"]]},{"id":"3bbe515a2e0f8c10","type":"function","z":"f6f2187d.f17ca8","name":"","func":"\nvar pl = {\n content: '/tmp/test.jpg',\n type : 'photo',\n chatId: 27960xxxx\n}\n\nmsg.payload = pl;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":520,"wires":[["90e8af0dac58027f"]]},{"id":"90e8af0dac58027f","type":"telegram sender","z":"f6f2187d.f17ca8","name":"","bot":"0385f759deab4c2f","haserroroutput":false,"outputs":1,"x":960,"y":520,"wires":[[]]},{"id":"c018db46f8e21c08","type":"image","z":"f6f2187d.f17ca8","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":580,"y":560,"wires":[]},{"id":"0385f759deab4c2f","type":"telegram bot","botname":"nrbot.fra","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

OKDaG commented 2 years ago

this loads an external jpg from wikimedia, result is the same error without sending the image

Bildschirmfoto 2021-10-02 um 09 13 24
windkh commented 2 years ago

I just tried your flow. It works here. Well I had to change the path to "c:/temp/test.jpg" because I am running under windows. So basically the image is ok and the flow, too. The only thing left is the file on the harddisc. Can you directly send the image without accessing the harddisc by just assigning the image buffer to content as follows content: msg.payload,

see also https://discourse.nodered.org/t/taking-a-picture-and-sending-it-via-telegram/27905/4

image

OKDaG commented 2 years ago

That's strange, i also tried it without storing the image on the harddisc, same error. nodered ist running here as a docker container, fresh installation on two different systems (both hosts ubuntu 20.04 with docker 20.10.7 running nodered/node-red:latest@sha256:ddd05759e91dce9db82d36a3df66011936cc49d59ac329589df379c44e74867e).

and that's also weird, tried it on raspi without docker and it works.

[{"id":"96f77d076a52f9a7","type":"inject","z":"f6f2187d.f17ca8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":240,"wires":[["1b6e18b0c16520ba"]]},{"id":"1b6e18b0c16520ba","type":"http request","z":"f6f2187d.f17ca8","name":"","method":"GET","ret":"bin","paytoqs":"ignore","url":"https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg","tls":"","persist":false,"proxy":"","authType":"","x":340,"y":240,"wires":[["c018db46f8e21c08","3bbe515a2e0f8c10"]]},{"id":"3bbe515a2e0f8c10","type":"function","z":"f6f2187d.f17ca8","name":"","func":"\nvar pl = {\n content: msg.payload,\n type : 'photo',\n chatId: 27960xxxx\n}\n\nmsg.payload = pl;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":240,"wires":[["90e8af0dac58027f","0e917861d78ecc2d"]]},{"id":"90e8af0dac58027f","type":"telegram sender","z":"f6f2187d.f17ca8","name":"","bot":"0385f759deab4c2f","haserroroutput":false,"outputs":1,"x":760,"y":240,"wires":[[]]},{"id":"c018db46f8e21c08","type":"image","z":"f6f2187d.f17ca8","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":560,"y":300,"wires":[]},{"id":"0e917861d78ecc2d","type":"debug","z":"f6f2187d.f17ca8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":200,"wires":[]},{"id":"0385f759deab4c2f","type":"telegram bot","botname":"nrbot.fra","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

windkh commented 2 years ago

Ah ok. So if you run inside docker you get the error in the sender node. Maybe we can get the callstack either via the console of node-red or maybe in the second output see

[{"id":"97bf33986b5f261d","type":"inject","z":"89e16d21b4d07ec8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":360,"wires":[["da8880f47da5782f"]]},{"id":"da8880f47da5782f","type":"http request","z":"89e16d21b4d07ec8","name":"","method":"GET","ret":"bin","paytoqs":"ignore","url":"https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg","tls":"","persist":false,"proxy":"","authType":"","x":400,"y":360,"wires":[["93060515c2cbc9af","f83b244d7eab6f7d"]]},{"id":"f83b244d7eab6f7d","type":"function","z":"89e16d21b4d07ec8","name":"","func":"\nvar pl = {\n content: msg.payload,\n type : 'photo',\n chatId: 27960xxxx\n}\n\nmsg.payload = pl;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":360,"wires":[["3b3301395ec8dd8d","7c392a3ea6058637"]]},{"id":"3b3301395ec8dd8d","type":"telegram sender","z":"89e16d21b4d07ec8","name":"","bot":"0385f759deab4c2f","haserroroutput":true,"outputs":2,"x":820,"y":360,"wires":[["09806b54e5e405fa"],["097f35116365c2a8"]]},{"id":"93060515c2cbc9af","type":"image","z":"89e16d21b4d07ec8","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":620,"y":420,"wires":[]},{"id":"7c392a3ea6058637","type":"debug","z":"89e16d21b4d07ec8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":320,"wires":[]},{"id":"097f35116365c2a8","type":"debug","z":"89e16d21b4d07ec8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1010,"y":380,"wires":[]},{"id":"09806b54e5e405fa","type":"debug","z":"89e16d21b4d07ec8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1010,"y":340,"wires":[]},{"id":"0385f759deab4c2f","type":"telegram bot","botname":"nrbot.fra","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

OKDaG commented 2 years ago

After reinstalling nodered and just install node-red-contrib-telegrambot the error is gone. Guess this is related to some other plugin. Will report which one if i found it.

windkh commented 2 years ago

Good news… yes please keep me informed

Speeedy0815 commented 2 years ago

Hi Guys,

I get the same error. Maybe you can help me. I'm running on RaspberryPi, no Docker.

Tryed to read first and forward the buffer. And I tryed also with filepath --> same error.

"Caught exception in sender node: Error: EFATAL: TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["getKeyByValue"] when processing message: "

I can not reinstall everything, because of running system here.

Can you help me?

Thank you.

windkh commented 2 years ago

@Speeedy0815 can you send me the image and the flow?

Speeedy0815 commented 2 years ago

Hi @windkh,

I sent you both via mail.

Thank you for your fast answer.

windkh commented 2 years ago

Hi, I had a look at your flow and found two things:

  1. If you use \ you have to escape it with a second \ in front of it: so always use \ when passing a path.
  2. Always use ' when passing a string property. Not anything like ´ or . In your flow the message was written like message:asde`,

Example that works for me

var payload = {
  content: 'C:\\Temp\\test.jpg',
  message:  'asde',
  type : 'photo',
  chatId: 12345678,
}

msg.payload = payload;
return msg;
Speeedy0815 commented 2 years ago

Hello @windkh,

Doesn't work.

  1. I have Linux paths with '/'. I don't have to escape them. (I tryed --> File not found)
  2. I changed the wrong "`", but it doesn't help. Same error.

Is it possible to get some more information? Can I debug something?

windkh commented 2 years ago

image

You can try this and send me the output. Please send me the image that you want to send via private email.

Speeedy0815 commented 2 years ago
  1. using path:
    {"_msgid":"bfaa219966764eba","payload":{"content":"/home/pi/bilder/g_s.jpg","message":"asde","type":"photo","chatId":120437710,"options":{"chat_id":120437710,"photo":null}},"error":"Caught exception in sender node:\r\nError: EFATAL: TypeError [ERR_INVALID_CHAR]: Invalid character in header content [\"getKeyByValue\"]\r\nwhen processing message: \r\n{\"_msgid\":\"bfaa219966764eba\",\"payload\":{\"content\":\"/home/pi/bilder/g_s.jpg\",\"message\":\"asde\",\"type\":\"photo\",\"chatId\":120437710,\"options\":{\"chat_id\":120437710,\"photo\":null}}}"}
  2. using buffer

{"_msgid":"ee8e0ae6a97b41fc","filename":"/home/pi/bilder/g_s.jpg","payload":{"content":[255,216,255,224,0,16,74,70,73,70,0,1,1,2,0,28,0,28,0,0,255,219,0,67,0,4,3,3,4,3,3,4,4,3,4,5,4,4,5,6,10,7,6,6,6,6,13,9,10,8,10,15,13,16,16,15,13,15,14,17,19,24,20,17,18,23,18,14,15,21,28,21,23,25,25,27,27,27,16,20,29,31,29,26,31,24,26,27,26,255,219,0,67,1,4,5,5,6,5,6,12,7,7,12,26,17,15,17,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,255,192,0,17,8,0,215,0,206,3,1,34,0,2,17,1,3,17,1,255,196,0,29,0,0,1,4,3,1,1,0,0,0,0,0,0,0,0,0,0,0,5,7,8,9,3,4,6,1,2,255,196,0,63,16,0,1,3,3,2,5,2,2,7,8,2,1,3,5,0,0,1,2,3,4,0,5,17,6,7,8,18,33,49,65,19,81,97,113,20,34,50,66,129,145,161,9,21,35,51,82,114,177,193,22,209,83,36,98,162,130,146,178,225,240,255,196,0,28,1,0,1,4,3,1,0,0,0,0,0,0,0,0,0,0,0,0,3,4,5,6,2,7,8,1,255,196,0,61,17,0,1,3,3,1,5,4,6,8,5,5,1,0,0,0,0,1,0,2,3,4,5,17,33,6,18,49,65,81,97,113,145,177,7,19,34,50,129,161,20,21,35,66,82,193,209,240,51,98,114,130,162,22,36,68,194,225,241,255,218,0,12,3,1,0,2,17,3,17,0,63,0,159,212,81,69,8,69,20,81,66,17,69,20,80,132,81,69,20,33,20,18,0,36,156,1,92,118,232,110,36,29,172,209,119,29,81,119,139,42,100,104,73,201,106,43,124,235,36,246,249,15,115,226,161,27,122,247,120,120,169,106,84,139,93,213,173,15,161,189,82,207,44,101,127,21,209,211,41,42,29,73,24,248,98,152,215,87,82,219,96,53,21,79,12,96,230,124,187,79,98,86,40,159,51,247,24,50,84,182,220,78,36,54,227,108,90,112,106,45,71,21,201,168,200,250,28,69,122,206,149,15,186,66,123,31,158,42,49,106,238,61,181,21,247,157,157,162,208,211,94,100,167,9,153,45,162,181,5,124,16,144,65,31,58,232,180,167,13,154,59,68,197,114,113,181,175,87,223,177,205,235,220,151,204,86,191,128,61,7,235,74,78,95,55,46,217,150,244,230,214,218,144,210,6,27,72,154,148,31,200,10,214,243,122,65,130,87,150,208,196,29,142,114,61,177,143,128,58,169,63,171,140,99,50,187,29,192,149,23,245,166,230,113,41,171,153,114,77,209,58,134,4,53,130,165,179,6,50,217,111,151,191,217,30,42,61,205,212,119,169,114,148,244,251,148,199,100,231,235,41,199,73,86,106,123,233,14,48,173,15,234,23,52,222,228,89,220,211,87,36,62,99,58,180,58,30,97,42,206,8,81,240,62,53,200,107,62,8,77,247,83,75,186,233,157,73,30,45,166,123,134,66,91,121,190,98,142,99,156,2,58,17,215,165,60,164,219,25,41,38,49,95,98,20,249,0,177,195,46,107,186,224,140,142,24,35,242,72,62,144,56,102,3,189,215,170,201,192,102,171,220,235,134,171,122,18,12,203,150,133,228,34,91,178,137,45,48,224,237,233,168,244,230,62,64,248,85,140,85,127,233,206,28,247,103,111,109,107,181,237,222,233,254,236,183,169,194,234,163,165,190,84,149,158,231,177,173,137,59,89,196,113,107,248,59,179,235,43,31,100,171,3,255,0,194,166,25,182,155,60,255,0,249,77,29,251,195,254,169,31,161,212,126,21,62,40,170,220,212,71,138,157,9,102,155,57,253,81,34,229,6,27,101,110,45,151,146,181,37,3,185,3,0,154,99,226,241,93,188,81,102,9,3,93,92,94,57,25,109,208,130,146,7,131,211,63,173,88,232,174,20,119,22,25,41,37,107,192,227,131,156,119,244,72,62,55,198,112,225,133,114,116,84,38,225,79,140,75,222,228,234,182,244,110,225,199,140,185,207,180,76,57,209,144,81,204,164,247,74,211,147,212,231,189,77,154,126,147,69,20,81,66,17,69,20,80,132,81,69,20,33,20,81,69,8,69,20,81,66,17,69,20,80,132,81,69,20,33,97,149,21],"message":"asde","type":"photo","chatId":120437710,"options":{"chat_id":120437710,"photo":null}},"error":"Caught exception in sender node:\r\nError: EFATAL: TypeError [ERR_INVALID_CHAR]: Invalid character in header content [\"getKeyByValue\"]\r\nwhen processing message: \r\n{\"_msgid\":\"ee8e0ae6a97b41fc\",\"filename\":\"/home/pi/bilder/g_s.jpg\",\"payload\":{\"content\":{\"type\":\"Buffer\",\"data\":[255,216,255,224,0,16,74,70,73,70,0,1,1,2,0,28,0,28,0,0,255,219,0,67,0,4,3,3,4,3,3,4,4,3,4,5,4,4,5,6,10,7,6,6,6,6,13,9,10,8,10,15,13,16,16,15,13,15,14,17,19,24,20,17,18,23,18,14,15,21,28,21,23,25,25,27,27,27,16,20,29,31,29,26,31,24,26,27,26,255,219,0,67,1,4,5,5,6,5,6,12,7,7,12,26,17,15,17,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,255,192,0,17,8,0,215,0,206,3,1,34,0,2,17,1,3,17,1,255,196,0,29,0,0,1,4,3,1,1,0,0,0,0,0,0,0,0,0,0,0,5,7,8,9,3,4,6,1,2,255,196,0,63,16,0,1,3,3,2,5,2,2,7,8,2,1,3,5,0,0,1,2,3,4,0,5,17,6,7,8,18,33,49,65,19,81,97,113,20,34,50,66,129,145,161,9,21,35,51,82,114,177,193,22,209,83,36,98,162,130,146..."}

windkh commented 2 years ago

I took the buffer and tried to send it:

image

However it seems that the image is not complete. So again: can you send me the picture as jpeg to my private email?

windkh commented 2 years ago

is this still an issue or can I close it? @Speeedy0815

Speeedy0815 commented 2 years ago

Hi @windkh,

I tryed it in Oktober after your mails. But it didn't work.

But I can't try it anymore because I haven't installed node-red-contrib-telegrambot anymore.

I use now node-red-contrib-telegrambot-home. (But here i can also not send photos)

I don't know what is wrong here. By the way --> sending via mail is working.....

So, thank you. You can close it.