Unfortunately, that doesn't seem to be the case. I have the database
user and password in my settings.py file, but I still have to do a
"sudo su postgres" to switch to postgres in the terminal before I can
access my PostgreSQL database through the Django database API.
Otherwise when I try to access it through my normal username
"guillaume", I get:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/django/db/models/
query.py", line 69, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/usr/local/lib/python2.7/dist-packages/django/db/models/
query.py", line 84, in __len__
self._result_cache.extend(self._iter)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/
query.py", line 273, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/
compiler.py", line 680, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/
compiler.py", line 734, in execute_sql
cursor = self.connection.cursor()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/
__init__.py", line 250, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/
postgresql_psycopg2/base.py", line 140, in _cursor
self.connection = Database.connect(**conn_params)
OperationalError: FATAL: Peer authentication failed for user
"postgres"
However, I found a way around the "out" file issue I mentioned
earlier; I did a search for my yaml file and changed the write
permission on it to all users, so I was then able to access it while
in the API under the postgres username. After I did so and attempted
to write serialized data to it, I got the following error:
>>> yaml_serializer.serialize(Player.objects.all(),stream=out)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/django/core/serializers/
base.py", line 55, in serialize
return self.getvalue()
File "/usr/local/lib/python2.7/dist-packages/django/core/serializers/
pyyaml.py", line 44, in getvalue
return self.stream.getvalue()
AttributeError: 'file' object has no attribute 'getvalue'
It does seem to have written to the yaml output file. In that, I got:
- fields: {age: 25, ast: 1, blk: 2, drb: 17, fg: 7, fga: 16,
first_name: Jeff, ft: 7,
fta: 12, gp: 8, last_name: Adrien, mp: 63, orb: 5, pf: 13, pos:
SF, pts: 21, stl: 0,
team: 1, three_pointers: 0, threes_attempted: 0, tov: 2}
model: players.player
pk: 1
But now I'm wondering what the error the API kicked was about...anyone
know?
thanks,
Guillaume
On Feb 17, 7:50 am, Bill Freeman <
ke1g...@gmail.com> wrote:
> The database user and *nix user are (typically) unrelated. The
> database user is specified in settings.py and there is also a password
> if necessary. Since one usually communicates with database servers
> using network connections (even on the same box), it doesn't really
> know what user a connection came from.
>
> Unless you are using sqlite3 as your database, in which case you just
> need to copy and change the ownership of the database file (may
> require sudo).
>