Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 problems with python script and special characters
im new to python and am trying to use the below script but when i run it i get this error:
IOError: [Errno 2] No such file or directory: '/root/user/split_=?Utf-8?Q?Temp_Glass/Mas_1213_Tempest?=\r\n =?Utf-8?Q?Tian/Kontakt_byr=C3=A5.mbox'
The python script is attached below. it analyzes an .MBOX file and split it into smaller .MBOX files based on the label name.
I've copied the script from here:

I think the issue is that its trying to create a folder structure but that fails. I actually dont care about the folder structure , i just need the splitted mbox files. Anyone have any ideas on how to rewrite this?

script is here in full

#!/usr/bin/env python

# Adapted from:

import sys
import getopt
import mailbox

def main(argv):
	in_mbox = "inbox.mbox"
	prefix = "split_"
		opts, args = getopt.getopt(argv, "i:p:", ["infile=", "prefix="])
	except getopt.GetoptError:
		print("python -i  -p ")

	for opt, arg in opts:
		if opt in ("-i", "--infile"):
			in_mbox = arg
		elif opt in ("-p", "--prefix"):
			prefix = arg
	print("Processing file - " + in_mbox + " with prefix = " + prefix)
	boxes = {"inbox": mailbox.mbox(prefix+"Inbox.mbox", None, True), "sent": mailbox.mbox(prefix+"Sent.mbox", None, True),"archive":mailbox.mbox(prefix+"Archive.mbox", None, True)}

	for message in mailbox.mbox(in_mbox):
		gmail_labels = message["X-Gmail-Labels"]       # Could possibly be None.
		if not gmail_labels:
		gmail_labels = gmail_labels.lower()
		if "spam" in gmail_labels:
		elif "inbox" in gmail_labels:
		elif "sent" in gmail_labels:
			saved = False
			for label in gmail_labels.split(','):
				if label != "important" and label != "unread" and label != "starred" and label != "newsletters":
					box_name = prefix+label.title()+".mbox"
					if box_name not in boxes:
						boxes[box_name] = mailbox.mbox(box_name, None, True)
					saved = True
			if not saved:

if __name__ == "__main__":
Yoriz wrote Mar-29-2019, 12:27 AM:
Please post all code, output and errors (in it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Hi last08, welcome to the forums! Could you please post the entire error message? It shows more valueable information.

I assume as you have not written this script yourself, but found it somewhere online, now you don't want to learn anything about it, but just have somebody repair it for you? Correct me, if I'm wrong.

The way to go about it would be, contact the author. If you are familiar with Github, you can file an issue there, and state the error message.

If you would indeed like to understand the script and repair it yourself, we are ready to help you up to speed. Please do ask questions where you lack understanding.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Pynput doesn't recognize shift button and special characters VirtualDreamer 0 208 Jul-17-2019, 11:55 AM
Last Post: VirtualDreamer
  Package python script which has different libraries as a single executable or script tej7gandhi 1 290 May-11-2019, 08:12 PM
Last Post: keames
  Slicing Python list of strings into individual characters Drone4four 5 506 Apr-17-2019, 07:22 AM
Last Post: perfringo
  modify the color a string of characters in python 3.6 atlass218 10 726 Feb-28-2019, 03:20 PM
Last Post: atlass218
  Replace characters from file in Python 2.7 melmouja 2 424 Feb-04-2019, 01:32 PM
Last Post: melmouja
  run setup.exe from python script with special parameters asheru93 0 318 Feb-01-2019, 03:11 PM
Last Post: asheru93
  IDLE crash using special characters? reikonaga 6 1,336 Aug-06-2018, 07:37 AM
Last Post: keegan_010
  Problems converting pyqt4 script to pyqt5 using Vysero 1 768 Jul-31-2018, 08:56 PM
Last Post: Axel_Erfurt
  Python regex with negative set of characters multiline sonicblind 2 564 Jul-30-2018, 08:43 PM
Last Post: sonicblind
  Issue with special characters Tiskolin 2 832 Mar-19-2018, 11:21 AM
Last Post: snippsat

Forum Jump:

Users browsing this thread: 1 Guest(s)