Not sure if OP figured out the problem. But I ran into similar situation and found an caveat, hope it helps someone:
I had the default AP enabled with IP address 192.168.4.1/24
I then enabled STA and connected to another AP, who **happened to assign IP address in the same subnet 192.168.4.0/24**
After successful connection, all name resolutions result in OSError -2.
The problem is resolved by either:
- Disable the ESP8266's AP, or
- configure ESP8266's AP to another subnet