# Fail to download maxmind db with valid key & can download the DB from inside container

**URL:** <https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590>\
**Category:** Bug\
**Tags:** maxmind\
**Created:** [March 22, 2024, 9:10pm UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590 "2024-03-22T21:10:47Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [March 22, 2024, 9:10pm UTC](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590/1 "2024-03-22T21:10:47Z")

</div>

The build failed because of this. I removed the ENV variable and rebuild without it. Then went to debugging inside the container. where I went and added the key to `discourse.conf`, it’s still failing.

(Thankfully I did this before telling the client that they’d given me an invalid key!)

I added a `puts` to the rake task to print the URL that it’s trying to download the database like this:

```plaintext
    url =
      "https://download.maxmind.com/app/geoip_download?license_key=#{GlobalSetting.maxmind_license_key}&edition_id=#{name}&suffix=tar.gz"

    gz_file =
      FileHelper.download(
        url,
        max_file_size: 100.megabytes,
        tmp_file_name: "#{name}.gz",
        validate_uri: false,
        follow_redirect: false,
      )

    if gz_file.nil?
      puts "no gzfile"
    end
    puts "Got file #{gz_file} for #{url}"
    filename = File.basename(gz_file.path)

```

Now I get this:

```plaintext
root@web-only:/var/www/discourse# rake maxminddb:get
Plugin name is 'discourse-topic-voting', but plugin directory is named 'discourse-voting'
Downloading MaxMindDb's GeoLite2-City...
no gzfile
Got file for https://download.maxmind.com/app/geoip_download?license_key=VALID_KEY_IS_HERE&edition_id=GeoLite2-City&suffix=tar.gz
rake aborted!
NoMethodError: undefined method `path' for nil:NilClass (NoMethodError)

    filename = File.basename(gz_file.path)
                                    ^^^^^
/var/www/discourse/lib/discourse_ip_info.rb:52:in `mmdb_download'
/var/www/discourse/lib/tasks/maxminddb.rake:9:in `block (2 levels) in <main>'
/var/www/discourse/lib/tasks/maxminddb.rake:7:in `each'
/var/www/discourse/lib/tasks/maxminddb.rake:7:in `block in <main>'
/usr/local/bin/bundle:25:in `load'
/usr/local/bin/bundle:25:in `<main>'
Tasks: TOP => maxminddb:get
(See full trace by running task with --trace)

```

There was another topic where the problem was that the site was blocked by Maxmind, so I tried, and successfully downloaded that URL with `wget` from inside the container on the server in question.

It seems to me that `FileHelper.download` isn’t much of a `Helper` after all and is silently returning `nil` instead of a file. The file is only 44MB, so that’s not it. When I check the full headers with wget I don’t see a redirect.

Any ideas what the deal could be?

Is there a reason not to catch this error and let a build complete with an invalid key? Maybe just print a warning?

---

_[View the full topic](https://meta.discourse.org/t/fail-to-download-maxmind-db-with-valid-key-can-download-the-db-from-inside-container/300590)._
