Python Forum
TypeError: initial_value must be str or None, not bytes
Thread Rating:
  • 3 Vote(s) - 3.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: initial_value must be str or None, not bytes
#1
Hello, I am new to Python, got my first script (that I found online) working. The problem is my PyCharm trail period has expired, so I just installed LiClipse and now my script doesn't work. The script extracts email addresses from your Inbox that's inside a folder:

#!/usr/bin/python

import imaplib
import sys
import email
import re

FOLDER = sys.argv[0]
FOLDER = "EMPLOYMENT3"
LOGIN = "emailaddresshere"
PASSWORD = "passwordhere"
IMAP_HOST = "imap.mail.yahoo.com"  # Change this according to your provider

email_list = []
email_unique = []

mail = imaplib.IMAP4_SSL(IMAP_HOST)
mail.login(LOGIN, PASSWORD)
mail.select(FOLDER)

result, data = mail.search(None, 'ALL')
ids = data[0]
id_list = ids.split()
for i in id_list:
	typ, data = mail.fetch(i,'(RFC822)')
	for response_part in data:
		if isinstance(response_part, tuple):
			msg = email.message_from_string(response_part[1])
			sender = msg['from'].split()[-1]
			address = re.sub(r'[<>]','',sender)
# Ignore any occurences of own email address and add to list
	if not re.search(r'' + re.escape(LOGIN),address) and not address in email_list:
		email_list.append(address)
		print(address)
This is the error message I get ever since I switched from PyCharm to LiClipse:



TypeError: initial_value must be str or None, not bytes
Reply


Messages In This Thread
TypeError: initial_value must be str or None, not bytes - by new2py - Aug-30-2017, 04:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: a bytes-like object is required ZeroX 13 5,014 Jan-07-2023, 07:02 PM
Last Post: deanhystad
  TypeError: a bytes-like object is required, not 'str' - Help Please. IanJ 3 5,072 Aug-29-2022, 05:53 PM
Last Post: deanhystad
  python 3: TypeError: a bytes-like object is required, not 'str' wardancer84 3 6,755 Jul-09-2021, 05:55 PM
Last Post: deanhystad
  TypeError: int() argument must be a string, a bytes-like object or a number, not 'Non Anldra12 2 5,395 May-02-2021, 03:45 PM
Last Post: Anldra12
  TypeError: a bytes-like object is required, not 'str' ozzy69 1 2,996 Jul-17-2020, 03:38 PM
Last Post: stullis
  Packet Sniffer - TypeError: a bytes-like object is required, not 'str' cheffa2020 4 5,487 Jun-12-2020, 02:10 PM
Last Post: cheffa2020
  Why, TypeError: expected string or bytes-like object ? JohnnyCoffee 3 18,779 May-08-2020, 04:26 AM
Last Post: bowlofred
  TypeError: a bytes-like object is required, not 'str'. jacklee26 4 5,841 Apr-18-2020, 11:04 PM
Last Post: jacklee26
  replace bytes with other byte or bytes BigOldArt 1 10,825 Feb-02-2019, 11:00 PM
Last Post: snippsat
  builtins.TypeError: a bytes-like object is required, not 'str' BigOldArt 0 4,057 Jan-31-2019, 10:46 PM
Last Post: BigOldArt

Forum Jump:

User Panel Messages

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