omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    pymongo.errors.ConfigurationError: Resolver configuration could not be read or specified no nameservers.

    Pythonista
    3
    9
    6354
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Penguin Master
      Penguin Master last edited by Penguin Master

      Hello, I'm trying to use PyMongo on Pythonista, and I got the link and all that right, but I'm getting this error:

      
      Traceback (most recent call last):
        File "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/spike-bot 4/main.py", line 34, in <module>
          db = pymongo.MongoClient("mongodb+srv://spike-bot:password@spike-db.bpn5m.mongodb.net/spike-db?retryWrites=true&w=majority")
        File "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/spike-bot 4/pymongo/mongo_client.py", line 641, in __init__
          connect_timeout=timeout)
        File "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/spike-bot 4/pymongo/uri_parser.py", line 500, in parse_uri
          nodes = dns_resolver.get_hosts()
        File "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/spike-bot 4/pymongo/srv_resolver.py", line 102, in get_hosts
          _, nodes = self._get_srv_response_and_hosts(True)
        File "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/spike-bot 4/pymongo/srv_resolver.py", line 83, in _get_srv_response_and_hosts
          results = self._resolve_uri(encapsulate_errors)
        File "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/spike-bot 4/pymongo/srv_resolver.py", line 79, in _resolve_uri
          raise ConfigurationError(str(exc))
      pymongo.errors.ConfigurationError: Resolver configuration could not be read or specified no nameservers.
      
      

      thanks

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        I gather it is complaining about the uri format (mongodb+srv://). Maybe try with just the host name?

        Penguin Master 3 Replies Last reply Reply Quote 0
        • Penguin Master
          Penguin Master @JonB last edited by

          @JonB Host name?

          1 Reply Last reply Reply Quote 0
          • ccc
            ccc last edited by ccc

            import platform
            print(platform.node())
            
            1 Reply Last reply Reply Quote 0
            • Penguin Master
              Penguin Master @JonB last edited by

              @JonB OK, I tried putting the host name, but it gives an error. I also tried doing mongodb:// instead of mongodb+srv:// but then it wouldnt connect. Any other ideas?

              1 Reply Last reply Reply Quote 0
              • Penguin Master
                Penguin Master @JonB last edited by

                @JonB also, the it needs to start with mongodb+srv:// or mongodb:// or it will say that it needs to be one of those

                1 Reply Last reply Reply Quote 0
                • JonB
                  JonB last edited by ccc

                  Ok, in second look, the issue seems to be dnspython. You should test whether dnspython works at all on pythonista. Try using it standalone.

                  You may be able to shim the dns resolver stuff, and just monkey patch to hard code whatever is expected...

                  1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB last edited by

                    indeed, the problem is that dnspython tries to open /etc/resolv.conf, which is forbidden on iOS.

                    luckily, dns.resolver lets you skip configuration, and configure the default resolver manually. so, the following should work -- do this before importing pymongo

                    import dns.resolver
                    dns.resolver.default_resolver=dns.resolver.Resolver(configure=False)
                    dns.resolver.default_resolver.nameservers=['8.8.8.8'] # this is a google public dns server,  use whatever dns server you like here
                    # as a test, dns.resolver.query('www.google.com') should return an answer, not an exception
                    

                    Just adde this code to the top of your main code, and that should be sufficient to get you past this hurdle..

                    Penguin Master 1 Reply Last reply Reply Quote 2
                    • Penguin Master
                      Penguin Master @JonB last edited by

                      @JonB thank you so much! It works perfectly!

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post
                      Powered by NodeBB Forums | Contributors