Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdhSb-0007jq-70 for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Jun 2019 20:45:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hdhSZ-00033T-WD for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Jun 2019 20:45:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdhSZ-00030Z-NX for pgsql-bugs@lists.postgresql.org; Wed, 19 Jun 2019 20:45:35 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdhS4-0007y0-M9 for pgsql-bugs@lists.postgresql.org; Wed, 19 Jun 2019 20:45:35 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x5JKiwUs023216; Wed, 19 Jun 2019 16:44:58 -0400 From: Tom Lane To: Jorge Gustavo Rocha cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15827: Unable to connect on Windows using pg_services.conf using Python psycopg2 In-reply-to: <81d9d421-6947-7111-a1dc-cfd99cd3ae53@geomaster.pt> References: <15827-e6ba53a3a7ed543c@postgresql.org> <82491.1559409563@sss.pgh.pa.us> <1473.1560866085@sss.pgh.pa.us> <81d9d421-6947-7111-a1dc-cfd99cd3ae53@geomaster.pt> Comments: In-reply-to Jorge Gustavo Rocha message dated "Wed, 19 Jun 2019 21:01:49 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <23214.1560977098.1@sss.pgh.pa.us> Date: Wed, 19 Jun 2019 16:44:58 -0400 Message-ID: <23215.1560977098@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jorge Gustavo Rocha writes: > The error I was facing in QGIS is because the application changes the > default fopen mode to binary mode. So, every file is opened in binary > mode and so is pg_services.conf. Ah-hah! That explains much. So a non-invasive fix would be to force parseServiceFile to open the file in text mode; I think this would work for that: - f = fopen(serviceFile, "r"); + f = fopen(serviceFile, "rt"); I don't think that that's really a good solution, because it does little to prevent the same problem from reappearing elsewhere. But if we wanted the smallest possible fix that might do. > In my humble opinion, we could make pg_services.conf agnostic in terms > of \r, just by filtering them, if present. I think we should have it go further and ignore any trailing isspace() characters, so that trailing spaces don't cause problems either. But in any case, the real stumbling block here is to get a project-wide convention as to how to do it. regards, tom lane