By adding two simple files in your home directory, you can access netCDF files with e.g. Python and Matlab via OPeNDAP without the need to put your credentials in the script.
The two required files are:
.netrc
machine <domain-or-ip-address> login <your-username> password <your-secret-password>
Note: the domain is the part of the url right behind http(s):// until the next / (see also the examples in the links mentioned below).
.dodsrc
HTTP.COOKIEJAR=<your-home-directory>/.cookies HTTP.NETRC=<your-home-directory>/.netrc
See http://docs.opendap.org/index.php/DAP_Clients_-_Authentication for more information. The explanation above is in particular based on http://docs.opendap.org/index.php/DAP_Clients_-_Authentication#Matlab.2C_Ferret.2C_Other_applications_that_use_NetCDF_C