1

I built a MacOS app using PythonKit to run some scripts and return the data. I had it running with no issues the other day but now it crashes when trying to load the script file. I've verfied the path to the file is correct and have run the Python script in Terminal with no issues.

Here's the error message:

Fatal error: 'try!' expression unexpectedly raised an error: Python exception: No module named 'helloswift': file PythonKit/Python.swift, line 674
2021-04-09 10:01:55.441796-0400 TechCommToolKit[10754:2952424] Fatal error: 'try!' expression unexpectedly raised an error: Python exception: No module named 'helloswift': file PythonKit/Python.swift, line 674

The line of code in PythonKit throwing it:

public func `import`(_ name: String) -> PythonObject { return try! attemptImport(name) }

My Python code in the file:

import requests
import json
import sys

def getConfluenceData(strEndPoint):

    s = requests.Session()

    response = s.post('https://wiki.xxxx.com/dologin.action', data={'os_username': 'app_wiki_api2', 'os_password': 'xxxxxxxxxxxxxxxx'})
    response = s.get(strEndPoint)

    json_formatted_str = json.dumps(response.json(), indent=4)

    return(json_formatted_str)
marc-medley
  • 8,931
  • 5
  • 60
  • 66
PruitIgoe
  • 6,166
  • 16
  • 70
  • 137
  • Could you please guide me , I'm trying to load python library which is not working - I am trying to run this demo https://rockyshikoku.medium.com/calling-python-scripts-from-swift-by-pythonkit-faf41757e890 where I am facing crash with `PythonKitBasics[44550:459091] PythonKit/Python.swift:674: Fatal error: 'try!' expression unexpectedly raised an error: Python exception: No module named youtube_dl` Thanks in Advance – Prashant Tukadiya Feb 25 '22 at 15:29
  • Sorry wrong link posted - here is the link https://github.com/anupamchugh/iowncode/tree/master/PythonKitBasics – Prashant Tukadiya Feb 25 '22 at 15:38

1 Answers1

0

Ug, this was operator error, I was pointing to the file, not the directory containing the file.

PruitIgoe
  • 6,166
  • 16
  • 70
  • 137