Raspi, Requests kennt weder .get noch .post

Sockets, TCP/IP, (XML-)RPC und ähnliche Themen gehören in dieses Forum
Antworten
attega
User
Beiträge: 12
Registriert: Samstag 4. April 2015, 22:17

Hallo zusammen,

ich möchte mit dem Raspi Daten per http anfragen.

Problem ist das das Python auf dem Raspi weder die get noch die post Methode kennt.

z.b. bei:

Code: Alles auswählen

import requests
url = 'http://192.168.178.53:8050/getOutputData'
x = requests.get(url)
print(x.text)
Funktioniert auf dem PC wie erwartet, auf dem Raspi bekomme ich als Fehlermeldung dass es keine methode get gibt.
Ebenso verhält es sich mit post.

Wobei beim Importieren des Module noch kein Fehler auftritt.

Wäre echt dankbar wenn jemand einen Tip hat, habe die letzten Abende schon das Internet durchforstet aber bisher keine möglichkeit für eine http Anfrage auf dem Raspi in Python gefunden.

Viele Grüße, Attega
Sirius3
User
Beiträge: 18249
Registriert: Sonntag 21. Oktober 2012, 17:20

Der komplette Traceback würde bei der Fehlersuche helfen.
Wahrscheinlich hast Du Deine eigene Datei requests.py genannt.
attega
User
Beiträge: 12
Registriert: Samstag 4. April 2015, 22:17

Guten Morgen,

eine Requests.py habe ich nicht.

Die Ausgabe sieht wie folgt aus:

Code: Alles auswählen

Traceback (most recent call last):
  File "/home/pi/Desktop/Wetter_Vorhersage/http.py", line 2, in <module>
    import requests
  File "/usr/lib/python3/dist-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/usr/lib/python3/dist-packages/urllib3/__init__.py", line 8, in <module>
    from .connectionpool import (
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 11, in <module>
    from ._collections import HTTPHeaderDict
  File "/usr/lib/python3/dist-packages/urllib3/_collections.py", line 18, in <module>
    from .exceptions import InvalidHeader
  File "/usr/lib/python3/dist-packages/urllib3/exceptions.py", line 2, in <module>
    from six.moves.http_client import (
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "/usr/lib/python3/dist-packages/six.py", line 203, in load_module
    mod = mod._resolve()
  File "/usr/lib/python3/dist-packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/usr/lib/python3/dist-packages/six.py", line 82, in _import_module
    __import__(name)
  File "/home/pi/Desktop/Wetter_Vorhersage/http.py", line 8, in <module>
    x=requests.get(url)
AttributeError: module 'requests' has no attribute 'get'
Wobei help(requests) folgene Ausgabe erzeugt:

Code: Alles auswählen

Help on package requests:

NAME
    requests

DESCRIPTION
    Requests HTTP Library
    ~~~~~~~~~~~~~~~~~~~~~
    
    Requests is an HTTP library, written in Python, for human beings. Basic GET
    usage:
    
       >>> import requests
       >>> r = requests.get('https://www.python.org')
       >>> r.status_code
       200
       >>> 'Python is a programming language' in r.content
       True
    
    ... or POST:
    
       >>> payload = dict(key1='value1', key2='value2')
       >>> r = requests.post('https://httpbin.org/post', data=payload)
       >>> print(r.text)
       {
         ...
         "form": {
           "key2": "value2",
           "key1": "value1"
         },
         ...
       }
    
    The other HTTP methods are supported - see `requests.api`. Full documentation
    is at <http://python-requests.org>.
    
    :copyright: (c) 2017 by Kenneth Reitz.
    :license: Apache 2.0, see LICENSE for more details.

PACKAGE CONTENTS
    __version__
    _internal_utils
    adapters
    api
    auth
    certs
    compat
    cookies
    exceptions
    help
    hooks
    models
    packages
    sessions
    status_codes
    structures
    utils

FILE
    /usr/lib/python3/dist-packages/requests/__init__.py
Sirius3
User
Beiträge: 18249
Registriert: Sonntag 21. Oktober 2012, 17:20

Statt dessen heist Deine Datei http.py, was die Standardbibliothek http überdeckt, die von requests benutzt wird.
nenne Deine Dateien so, dass es zu keinen Konflikten kommt.
Antworten