aktuell bin ich in meinem Pythonbuch im Kapitel JSON.
Diese kleine Skript:
Code: Alles auswählen
import json
from urllib.request import urlopen
ID = "365732826eb5f25bb6da21b0f4355337" #1
URL = "http://api.openweathermap.org/data/2.5/weather?zip={},de&APPID={}"
REPORT = """
Wetterbericht für {}:
Temperatur: {:.1f} °C
Lufdruck: {:.1f} bar
"""
print("Geben Sie die Postleitzahl einer Stadt in Deutschland ein.")
city = input("PLZ: ")
while city: #3
try:
f = urlopen(URL.format(city, ID)) #4
data = json.load(f) #5
name_city = data["name"]
temp = data["main"]["temp"]-273.15 #6
pressure = data["main"]["pressure"]
print(REPORT.format(name_city, temp, pressure)) #7
except:
print("Fehler. Vielleicht war die Postleitzahl ungültig.")
city = input("PLZ: ")
print("Auf Wiedersehen!")
Öffne ich das Skript aus dem Download funktioniert es einwandfrei.
Wenn ich aber ein neues Fenster öffne und den Text abtippe oder auch direkt rüber kopiere funktioniert es nicht.
Diesen Fehler erhalte ich:
Code: Alles auswählen
Python 3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
>>>
======= RESTART: /mnt/sda5/scripts/python/Buch/26 XML und JSON/wetter.py =======
Traceback (most recent call last):
File "/usr/lib/python3.8/idlelib/run.py", line 559, in runcode
exec(code, self.locals)
File "/mnt/sda5/scripts/python/Buch/26 XML und JSON/wetter.py", line 8, in <module>
from urllib.request import urlopen
File "/usr/lib/python3.8/urllib/request.py", line 88, in <module>
import http.client
File "/usr/lib/python3.8/http/client.py", line 71, in <module>
import email.parser
ModuleNotFoundError: No module named 'email.parser'; 'email' is not a package
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 72, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 21, in <module>
from urllib.request import urlopen
File "/usr/lib/python3.8/urllib/request.py", line 88, in <module>
import http.client
File "/usr/lib/python3.8/http/client.py", line 71, in <module>
import email.parser
ModuleNotFoundError: No module named 'email.parser'; 'email' is not a package
Habe bereits den Rechner neu gestartet und Python neu installiert.
Schönen Dank schon mal an all die die ich ins grübeln gebracht habe.