ValueError: source code string cannot contain null bytes

0 views
Skip to first unread message

wizar...@gmail.com

unread,
Apr 20, 2018, 10:56:37 AM4/20/18
to Anaconda - Public
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 6.2.1 -- An enhanced Interactive Python.
runfile('C:/daten/python/inliner.py', wdir='C:/daten/python')
Traceback (most recent call last):
  File "<ipython-input-1-1369c7b455c1>", line 1, in <module>
    runfile('C:/daten/python/inliner.py', wdir='C:/daten/python')
  File "C:\Anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)
  File "C:\Anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)
ValueError: source code string cannot contain null Bytes

Hallo Gemeinde,
komme hier nicht weiter.
Wenn ich das Programm mit dem Pfeil nach rechts starte kommt obiger Fehler.
Wenn ich im Einzelschrittmodus das Programm abarbeite läuft es ohne Probleme und bringt mir 
auch das erwartete Ergebnis.

Verwende: Spyder

Ich weiss nicht was ich machen soll, bitte um dringende Hilfe.

Grüße
Eduard




Sourcecode:
from bs4 import BeautifulSoup
from functionen import simple_get
URL='https://www.sg-zertifikate.de/de/product.html?isin=DE000SC73XH7'
raw_html = simple_get(URL)
soup = BeautifulSoup(raw_html, 'html.parser')
Basispreis1 = soup.find('div', attrs={'class': 'detail-reference__number'})
Basispreis = Basispreis1.text.strip()
print (Basispreis)


functionen.py

from requests import get
from requests.exceptions import RequestException
from contextlib import closing

def simple_get(url):
    """
    Attempts to get the content at `url` by making an HTTP GET request.
    If the content-type of response is some kind of HTML/XML, return the
    text content, otherwise return None
    """
    try:
        with closing(get(url, stream=True)) as resp:
            if is_good_response(resp):
                return resp.content
            else:
                return None
    except RequestException as e:
        log_error('Error during requests to {0} : {1}'.format(url, str(e)))
        return None

def is_good_response(resp):
    """
    Returns true if the response seems to be HTML, false otherwise
    """
    content_type = resp.headers['Content-Type'].lower()
    return (resp.status_code == 200
            and content_type is not None
            and content_type.find('html') > -1)

def log_error(e):
    """
    It is always a good idea to log errors.
    This function just prints them, but you can
    make it do anything.
    """
    print(e)
   
raw_html = simple_get('https://realpython.com/blog/')
len(raw_html)
   
Reply all
Reply to author
Forward
0 new messages