Python Forum
AttributeError: 'NoneType' object has no attribute error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: 'NoneType' object has no attribute error
#1
I am writing a python script for scrapping weather of different city from weather-forecast website. I got an AttributeError in my code and i am unable to gets the cause of error.

Here is my code:

import urllib.request, urllib.parse, urllib.error
import ssl
import re

# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

condition = 1
braces = '<'

while(condition):
    end = 0
    start = 0
    city = input('enter city: ')
    url = "http://www.weather-forecast.com/locations/" + city + "/forecasts/latest"
    rawData = urllib.request.urlopen(url, context=ctx).read()
    data = rawData.decode()
    string = re.search('1 &ndash; 3 Day Weather Forecast Summary:</b><span class="read-more-small"><span class="read-more-content"><span class="phrase">', data)
    start = string.end()

    i = 0
    for i in range(start,start+500):
        if data[i] == braces:
            end = i
            break

    weather = data[start:end]
    final = weather.replace("&deg;C"," °C")
    print(final)
    print("")
This is an error occured:
Error:
enter city: Mumbai Traceback (most recent call last): File "C:\Users\VISHAL\Desktop\wf\weather.py", line 21, in <module> start = string.end() AttributeError: 'NoneType' object has no attribute 'end'
Reply


Messages In This Thread
AttributeError: 'NoneType' object has no attribute error - by vk7 - Feb-02-2018, 08:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to fix "'dict_values' object has no attribute 'inject_wsgi'" in session_transacti devid 0 1,197 Aug-13-2023, 07:52 AM
Last Post: devid
  AttributeError: 'ellipsis' object has no attribute 'register_blueprint' Mechanicalpixelz 2 2,423 Dec-29-2021, 01:30 AM
Last Post: Mechanicalpixelz
  AttributeError: 'NoneType' object in a parser - stops it apollo 4 4,051 May-28-2021, 02:13 PM
Last Post: Daring_T
  AttributeError: ResultSet object has no attribute 'get_text' KatMac 1 4,405 May-07-2021, 05:32 PM
Last Post: snippsat
  Python 3.9 : BeautifulSoup: 'NoneType' object has no attribute 'text' fudgemasterultra 1 8,942 Mar-03-2021, 09:40 AM
Last Post: Larz60+
  'NavigableString' object has no attribute 'h2' RandomCoder 5 5,430 May-20-2020, 09:01 AM
Last Post: Larz60+
  AttributeError: 'str' object has no attribute 'xpath' nazmulfinance 4 10,512 Nov-11-2019, 05:15 PM
Last Post: nazmulfinance
  AttributeError: 'str' object has no attribute 'xpath' nazmulfinance 0 3,087 Nov-10-2019, 09:13 PM
Last Post: nazmulfinance
  form.populate_obj problem "object has no attribute translate" pascale 0 3,662 Jun-12-2019, 07:30 PM
Last Post: pascale
  Error object has no attribute text hcyeap 3 13,939 May-21-2019, 07:12 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020