Error 403 when using local files - referer missing - can I use User Agent and what should it contain

Hilariously, I see your screenshot as:

You can normally just drag and drop screenshots into Discourse (although that might be limited until people have posted a bit for obvious regions).

I have merged this topic into one of the others that describes the problem - please scroll up to look at the options you have.

Edit: To explain the “not available” - Imgur broke the law and don’t want to pay the fine.

Thanks for the reply. Not being able o see the image is strange. It’s hosted in imgur, a well known and very used server to post images! But it doesn’t mater. The image is similar to the one from user @holeu above.

I think my problem is specifically tied to the Qt QWebEngineView widget. It’s using a static page to display OSM map tiles, that I know. If I put the exact same page in my webserver and point my application to use that one to access OSM servers things work correctly.

Nonetheless, some of the answers in the posts above gave me some ideas to try to tackle this proble. I only wonder why the error does not pop up when using OSM server in Germany (I haven’t tested others). Could this be related to the fact that I’m in Europe?

That is because different tileservers have different technical means to enforce their tile usage policies.

But instead of hunting for one where it (still) works I’d recommend to fix the software so that it adheres to the osmf tile usage policy.

Of course you are right, and that’s what I’m trying to do. In Qt6 I discover that I can set the headers using a specific class (QWebEngineHttpRequest)

QWebEngineHttpRequest request;
request.setUrl( QUrl( "qrc:/html/index.html" ) );
request.setHeader("Referer","https://fake.site.com");
QWebEngineView *view = new QWebEngineView;
view->load(request);

Note the URL, which is a Qt resource (a simple html page embedded in the executable). But what to use as a Referrer in the `Referer header’? This is a prototype application. It will eventually have a Codeberg repository. But should I use it as the referrer? I’ve tried with an old but existent GitHub repository (not related with this project) and I still get the error!

Setting fakes will not help. Rather think about setting a unique User Agent that would have you easily identified, maybe even with contact mail. So the osmf working group could identify you and contact you if they see a misuse. Otherwise they only have a chance in blocking requests if they see a misuse.

I’m sorry, I probably didn’t make myself clear: I haven’t used the fake example displayed above. I’ve tried the software with a true github URL, which is obviously unique, but it’s from a different project not related with this one. At this stage, this software has not yet a remote git repository. But using the unique github repository didn’t make any difference. The error still pops-up once in a while.

I think I’ll leave OSM servers alone and use a simple SVG world map rendered with Qt SVG widgets. I already managed to write the widget and render an SVG map since I started this thread. This way, mapping will be totally independent from internet connection. Now I only have to translate lat/long coordinates (of observations) into the SVG widget coordinates.

But thank you anyway. OSM is great, and for GPS purposes I excusively use OsmAnd~, not GMaps!

If you use it in browser, viewing file from server (not from file://) then by default it will send referer.

If it is not sending one, then something blocks it

It may be useful to look at the Tile Usage Policy as it looks like it has been updated. The link is

not really, see https://github.com/openstreetmap/owg-website/commits/fd9fec07d48c4da69e617379a7006e5b2fbd08b6/policies/tiles.md for update list

there were readability tweaks and giving more helpful hints but changes to actual policy rules last happened quite long time ago

Is there any technical possibility to view OSM tiles from within a HTML file on local file opened by a browser (Firefox)? The mentioned solution is not applicable, as above the application is the browser and can be tweaked. I want to use a real unmodified browser. And I prefer to open the html from file:// and not run a webserver (also no tiny one).

I can’t modify UserAgent from within a page. This would require add-ons in the browser.

I can’t set a referrer to a value, as this is blocked by the browser

By default it does not send any referrer for file:// URLs.

I can replace Tile layer with a custom one to pass details to fetch(), but even setting referrerPolicy to “origin” fails to send a referrer as browser does not send it, probably due to CORS null-origin

I would look through Raster tile providers - OpenStreetMap Wiki and check their tile usage policies. If they have nothing published - maybe just check how things work.

Maybe currently not all require referer?

If none of them work you can try Vector tiles - OpenStreetMap Wiki and if that fails you can run own tile server or pay someone to do this for you.

How do I do this in python? I’m getting 403r through a local html page generated with geopandas and mapclassify/folium. I can’t find any good documentation or forum posts about how to create a user agent to send in a request with python.

Are you trying to bulk download tiles with python script? Or are tiles downloaded when web browser opens that local file?

I think the tiles are downloaded when the browser opens the file? I just used this page as an example. Mapping Census Data with Python – Policy, Politics, and Data

I saved it as an html file and opened it because I wanted to try adding the map I generate to the website, but I don’t know the correct way to do that yet. It doesn’t show 403r when I run the code in jupyterlab.

With my local (file:///) leaflet based html files I’ve been trying out other tileservers:

<!-- L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { -->
L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
<!-- L.tileLayer('https://tile.openstreetmap.de/{z}/{x}/{y}.png', { -->
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map); 

The ‘main mapnik’ is the only server from which I’m missing tiles.
Could others confirm?

As we’re only missing the occasional, random tile doesn’t it suggest the problem is server-side?

Blocking tiles without referer is intentionally done on OSM Carto servers run by OSMF.
Yes, maps in local html files are blocked as side-effect

Other tile servers have different tile usage policies or currently they are not enforcing referer requirement

Is the occasional, random missing tile intended coding by OSM-carto?

Are those of us who create local htmls for their own leaflet maps, usually with minimum tile usage, the actual culprits who are abusing the system?

if it is replaced by error message then yes, if not then providing query + response logs is needed to investigate

no, but are unintended victims of mitigations employed to stop them

So there’s a blanket restriction because, once again, OSMF & OSM-carto aren’t competent enough to write efficient code to solve a problem,

Explain why I shouldn’t feel victimised on being blamed & punished for something I’ve not done or have any control over.

What SLA do you have with them?

If no SLA, why do they owe you a “free pony”?