PST | Not able to convert .ics file to PST getting error | Proxy error(UriFormatException): Invalid URI: The hostname could not be parsed

Not able to convert .ics file to PST format using aspose lib getting below error.

C:\Users\Tejas>python calendarissue.py
Traceback (most recent call last):
File “mailissue.py”, line 57, in
run()
File “mailissue.py”, line 49, in run
appointment = Appointment.load(f.file_directory)
Proxy error(UriFormatException): Invalid URI: The hostname could not be parsed

Code

from aspose.email import MailMessage
from aspose.email.mime import HeaderCollection
import aspose.email.mapi.msg as msg
from aspose.email.mapi import MapiMessage, MapiContact
from aspose.email.personalinfo.vcard import VCardContact
import aspose.email as ae
import os
import shutil
import tempfile
from aspose.email.calendar import Appointment

class TempFileManager:
    """
    Manager that creates a file in temporary directory. Removes temporary directory on exit.
    """

    def __init__(self, file_content, file_name):
        self.content = file_content
        self.file_name = file_name

    def __enter__(self):
        self.folder_directory = tempfile.mkdtemp()
        self.file_directory = os.path.join(self.folder_directory, self.file_name)
        with open(self.file_directory, "w+", encoding="utf-8-sig") as f:
            f.write(self.content)
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        shutil.rmtree(self.folder_directory)



def prepare_file(file_dir):
	with open(file_dir, "r+", encoding="utf-8-sig") as f:
		readed_file = f.read()
		readed_file = readed_file.replace("ACTION:Display\n", "ACTION:DISPLAY\n")
	return readed_file

def run():

	#dataDir = "Data/"
	#ExStart: LoadingContactFromVCardWithSpecifiedEncoding
	#print(MailMessage.load('Undeliverable_ repro test-1727695419 (2).eml'))
	#result = MapiMessage.from_mail_message(MailMessage.load('Undeliverable_ repro test-1727695419 (2).eml'))
	#print(result)
	#ExEnd: LoadingContactFromVCardWithSpecifiedEncoding
	prepared_file = prepare_file('testinvalidmail.ics')
	with TempFileManager(prepared_file, os.path.basename('testinvalidmail.ics')) as f:
  		appointment = Appointment.load(f.file_directory)
	mail_message = ae.MailMessage()
	mail_message.add_alternate_view(appointment.request_apointment())
	mapi_message = MapiMessage.from_mail_message(mail_message)
 

	
if __name__ == '__main__':
    run()

@TejasA

The error you’re encountering, UriFormatException: Invalid URI: The hostname could not be parsed, indicates a potential issue with the format of the .ics file or the way it is being loaded. Here are several steps to troubleshoot and resolve the issue:

  1. Check the .ics File Format: Verify that the .ics file adheres to the iCalendar specification. Any malformed lines or incorrect syntax can lead to parsing errors.

  2. File Path Verification: Ensure that the file path you are providing to Appointment.load() is correct and accessible. You can print the f.file_directory to confirm the path.

  3. Use Absolute Path: If you are using a relative path, consider switching to an absolute path to avoid any path resolution issues.

  4. Debugging: Add print statements to inspect the content of the prepared_file before loading it. This can help identify any unexpected characters or formatting issues.

  5. Minimal Example: If the issue persists, create a minimal .ics file with a simple appointment to see if it loads correctly. This can help determine if the problem lies within the specific file you are using.

Here’s a simple example of a basic .ics file:

BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SUMMARY:Test Event
DTSTART:20240101T090000Z
DTEND:20240101T100000Z
END:VEVENT
END:VCALENDAR

Try loading this simple .ics file to see if the error still occurs. If it works, the issue likely resides within the content of the original .ics file.

There is no issue with the .ics file, and we have checked all the above things.

Thank you for confirming.

@margarita.samodurova any update on this ?

Hello @TejasA,

We would still need a sample .ics file that reproduces the issue in order to investigate further. Could you please share a minimal example (with sensitive information removed) so that we can test it on our side?

Thank you.