Python 3 – die besten Beiträge

Datei finden Fehler?

Hallo,

ich mache ein Programm in Python (mit Turtle), welches erkennt wo die ISS ist. Aber (obwohl es in demselben Ordner ist) findet es die Datei 'map.gif' nicht. Kann mir da jemand helfen?

Danke im voraus!

Code:

import json
import turtle
import urllib.request


url = 'http://api.open-notify.org/astros.json'
antwort = urllib.request.urlopen(url)
ergebnis = json.loads(antwort.read())


print('Personen im Weltall: ', ergebnis['number'])


personen = ergebnis['people']
#print(personen)



for p in personen:
    print(p['name'], 'in', p['craft'])


url = 'http://api.open-notify.org/iss-now.json'
antwort = urllib.request.urlopen(url)
ergebnis = json.loads(antwort.read())


standort = ergebnis['iss_position']
breitengrad = float(standort['latitude'])
längengrad = float(standort['longitude'])
print('Breitengrad: ', breitengrad)
print('Längengrad: ', längengrad)


bildschirm = turtle.Screen()
bildschirm.bgpic("map.gif")

Fehlermeldung:

File "/home/pi/Dokumente/Python programme/Standart/Wo ist die ISS?", line 29, in <module>
    bildschirm.bgpic("map.gif")
  File "/usr/lib/python3.7/turtle.py", line 1481, in bgpic
    self._bgpics[picname] = self._image(picname)
  File "/usr/lib/python3.7/turtle.py", line 479, in _image
    return TK.PhotoImage(file=filename)
  File "/usr/lib/python3.7/tkinter/__init__.py", line 3545, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "/usr/lib/python3.7/tkinter/__init__.py", line 3501, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "map.gif": no such file or directory
Python, Python 3, Tkinter

DOCKER Fehlermeldung: TypeError: function() argument 'code' must be code, not str, was tun?

Hallo, ich mit einem YouTube video eine kleine FastApi App geschrieben. Dann habe ich sie als ein Docker gebaut. Wenn ich diesen nun starte bekomme ich die im Titel stehende Fehlermeldung. `Ich habe schon ganz Google nach einer Möglichkeit durchgesucht aber leider keine Lösung gefunden. Vll. hat ja einer von euch 'ne Idee.

DER CODE:

from fastapi import FastAPI
from app.model.test import Upscale

app = FastAPI()

class TextIn(Upscale):
    org_url: str


class TextOut(Upscale):
    url: str



@app.get("/")
def home():
    return {"health_check": "OK"}

@app.post("/post", response_model=TextOut)
def UpSc(payload: TextIn):
    textwrap = Upscale(payload.org_url)
    return {"url": "url"}

`

KOMPLETTER TRACEBACK: `

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.9/site-packages/uvicorn/workers.py", line 66, in init_process
    super(UvicornWorker, self).init_process()
  File "/usr/local/lib/python3.9/site-packages/gunicorn/workers/base.py", line 134, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.9/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.9/site-packages/gunicorn/util.py", line 359, in import_app
    mod = importlib.import_module(module)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/app/app/main.py", line 6, in <module>
    class TextIn(Upscale):
TypeError: function() argument 'code' must be code, not str

in meinen requirements.txt steht:

fastapi
boto3
opencv-contrib-python-headless
opencv-python-headless
numpy

ich nutzte Python 3.9 habe es aber auch ohne Erfolg mit anderen Version probiert.

Python, Python 3, Docker

Meistgelesene Beiträge zum Thema Python 3