Where is python being invoked from, another container? If so the two containers would need to be on the same docker network and the host in the connection string would be mongodb://mongodb
If python is being invoked on the host computer, it looks like it should work. But there could be some docker configuration or firewall that needs updating.