Python Forum
Problem with sending text file as an attachment using this Gmail OAuth script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with sending text file as an attachment using this Gmail OAuth script
#5
Quote:To fix you have 2 options, you can try to read line by line (by using readline) and add "\r\n" in the end of each line.
Or you can try to open the Text File in binary mode:

Python Code: (Double-click to select all)
if main_type == 'text':
       print("text")
       temp = open(attached_file, 'rb')  # 'rb' will send this error: 'bytes' object has no attribute 'encode'
       attachement = MIMEText(temp.read(), _subtype=sub_type)
       temp.close()
I didn't test the solution above, but you can give a try and see if it Works.

Using 'rb' will send an error 'bytes' object has no attribute as it's mentioned in the comment besides the code you posted. How would the code be with readline?
Reply


Messages In This Thread
RE: Problem with sending text file as an attachment using this Gmail OAuth script - by downloaderfan - Feb-07-2018, 04:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Script problem - Illegal access to removed OSM object MarcPolo72 0 937 Jun-23-2024, 04:26 PM
Last Post: MarcPolo72
  Sending a text from Python sawtooth500 2 1,124 Apr-14-2024, 01:56 PM
Last Post: sawtooth500
  very newbie problem on text file zapad 2 1,047 Apr-12-2024, 06:50 PM
Last Post: zapad
  Unable to download TLS Report attachment blason16 6 1,816 Feb-26-2024, 07:36 AM
Last Post: Pedroski55
  Script that alternates between 2 text messages DiscoMatic 1 1,268 Dec-12-2023, 03:02 PM
Last Post: buran
  Extract PDF Attachment from Gmail jstaffon 0 1,568 Sep-10-2023, 01:55 PM
Last Post: jstaffon
  Python script that deletes symbols in plain text nzcan 3 1,678 Sep-05-2023, 04:03 PM
Last Post: deanhystad
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 2,015 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Sending Whatsapp Message in the text file ebincharles869 9 5,967 Jun-21-2022, 04:26 PM
Last Post: snippsat
  Modify values in XML file by data from text file (without parsing) Paqqno 2 3,153 Apr-13-2022, 06:02 AM
Last Post: Paqqno

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020