0

I have at the moment to figure out where "favicon.ico" comes from. It is really super weird.

I use geopy to geocode a location into latitude and longitude, then I use these values to create markers on a google map (Flask GoogleMaps).

That is the piece of code:

try:
    print findroomcity
    location = geolocator.geocode(findroomcity)
    print location, location.latitude, location.longitude

    if location:
        mymap = Map(
        identifier="view-side",
        lat=location.latitude,
        lng=location.longitude,
        markers=[(location.latitude, location.longitude)],
        zoom = 12
        )
    else:
        print "location is none"

In this case findroomcity is "dortmund". It is actually grabbed from a form.

If I submit the form the map is actually created, so it does not use the else block But it tells me that location in NoneType and has no attribute latitude. It seems that it calls the try block three times and the first time findroomcity is "favicon.ico", also the last time

Check the outputs of the prints: enter image description here

I dont even used "favicon.ico" in my whole project, I know it must be somewhere but I checked every .py file and also searched for every print. I am really super confused, I keep searching, but maybe someone has encountered something similar.

Here is the whole method which creates the map:

# Die Filter Funktion mit Google Maps
@app.route('/<findroomcity>', methods=["GET", "POST"])
def find_room(findroomcity):
    form = FilterZimmerForm()

    if form.validate_on_submit():

        query = Zimmer.query
        filter_list = ["haustiere_erlaubt","bettwaesche_wird_gestellt","grill_vorhanden","safe_vorhanden","kuehlschrank_vorhanden","rauchen_erlaubt","parkplatz_vorhanden",
                "kochmoeglichkeit_vorhanden","restaurant_im_haus_vorhanden","handtuecher_werden_gestellt","tv_vorhanden","waschmoeglichkeit_vorhanden","wlan_vorhanden"]

        for filter_name in filter_list:
            if getattr(form, filter_name).data:
                query = query.filter(getattr(Zimmer, filter_name).is_(True))

        all_rooms_in_city = query.all()

        else:
            all_rooms_in_city = Zimmer.query.order_by(desc("stadt")).all()  


        try:
            print findroomcity
            location = geolocator.geocode(findroomcity)
            print location, location.latitude, location.longitude

            if location:
                mymap = Map(
                identifier="view-side",
                lat=location.latitude,
                lng=location.longitude,
                markers=[(location.latitude, location.longitude)],
                zoom = 12
                )
           else:
               print "location is none"



        except AttributeError as e:
            flash("Ort nicht gefunden")
            print e
            return redirect(url_for('index'))
        except GeocoderTimedOut as e:
            print e

    sleep(1)
    return render_template('zimmer_gefunden.html', mymap=mymap, all_rooms_in_city=all_rooms_in_city, findroomcity=findroomcity, form=form)

EDIT

I have really no idea where it comes from, I use now:

if location.latitude is not None:
Roman
  • 3,563
  • 5
  • 48
  • 104
  • I have not used Flask but googling "flask favicon.ico 404" gives you the documentation to specifically address this error http://flask.pocoo.org/docs/0.11/patterns/favicon/ – roganjosh Jul 07 '16 at 09:08
  • What does this have to do with my question? I know how to add a favicon in flask... – Roman Jul 07 '16 at 09:11
  • But why it prints it there and why geolocator tries to create a latidute from the the "favicon.ico" string? If I add the favicon the error disappears of course. – Roman Jul 07 '16 at 09:21
  • Can u post your template code? – Iron Fist Jul 07 '16 at 09:34
  • The Issue is solved, the template is really huge and SO code block does not format it right so I would need 20 min to intend everything, I still dont know why geopy printed favcion, but including favicon solved the issue, btw @roganjosh if you answer it, I`ll accept – Roman Jul 07 '16 at 12:04

0 Answers0