0

I'm trying to figure out what is wrong with my code, sometimes it works sometimes it doesn't, I don't know how to debug it when it doesn't work.

Basically I'm working with this code:

uri = QgsDataSourceUri()
uri.setConnection(str(host), str(port), str(dbname), str(username), str(password))
uri.setDataSource(str(schema), str(table), str(geom_col), '', 'field_row_id')
uri.setKeyColumn('field_row_id')
uri.setSrid('4326')
vlayer = QgsVectorLayer(uri.uri(), str(extra_name) + str(table), 'postgres')
print(uri.uri())

Prints something like this: 'dbname=\'hortegarden\' host=geodatafarm.com port=5432 user=\'my_username\' password=\'my_password\' key=\'field_row_id\' srid=4326 table="harvest"."dyback_2015" (pos) sql='

field_row_id is a valid primary key with unique values. I can add the table from the source manager, hence I want it to be apart of my plugin. Though the source from the working layer properties looks like this: dbname='hortegarden' host=geodatafarm.com port=5432 sslmode=disable authcfg=0xq253x key='field_row_id' srid=4326 type=Point table="harvest"."dyback_2015" (pos) sql=

Any suggestion how I can investigate why it is not valid?

closed as off-topic by user2856, BERA, tinlyx, whyzar, aldo_tapia Apr 9 '18 at 11:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – user2856, BERA, tinlyx, whyzar, aldo_tapia
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Maybe try to add the table from the source manager, copy the source string in the general tab of the layer property and past it instead of 'uri.uri()' ? What happens? Is this source string different from the 'uri.uri()' ? – Oscar Campo Apr 6 '18 at 15:18
  • I added the connection info from the property of the working layer and the output from uri.uri() – axel_ande Apr 8 '18 at 7:57
0

Bah, the problem was an unstable wifi connection :(

Not the answer you're looking for? Browse other questions tagged or ask your own question.