Possible MySQL authentication issue with python package (PyMySQL3) - python

I actually found a blog post that pretty much sums up my problem. Its at
http://simon04.net/2013/03/python3-mysql/
The blog post is the most clear but to summarize: I'm currently trying to access a remote MySQL database with a python package called PyMySQL3. However I keep getting the error: "AttributeError: 'bytes' object has no attribute 'encode'". From the blog post above and some other research, I think this has to do with my database having an old authentication method.
However, I'm confused because it looks like the old authentication method was phased out sometime in MySQL 4.0. The database I have runs MySQL 5.0.51a. Shouldn't my database have the correct authentication?
I've been working on this awhile and getting a little frustrated. Hopefully someone can help. Thanks,

From https://github.com/petehunt/PyMySQL/issues/64
For me this problem was due to the usage of the old authentication
method (cf.
http://dev.mysql.com/doc/internals/en/authentication-method.html).
Creating a new user (resetting the password might work as well) and
making sure that the password column for this user in the mysql.user
table starts with a * (otherwise check the server configuration
according to the above link), solved the problem for me.
Have you created the users with this very Version you mentioned?
The thread shows how to fix the problem in the code aswell, tellme when you need additional help to fix it. I would edit my answer accordingly.

Ok, while investigating this more I thought that maybe my hosting company (aplus.net) just wasn't up to date. I was going to switch companies anyways and so I opened a new account with another company. Now I have no problems connecting with PyMySQL3. So apparently, my old hosting company just wasn't up to date or at least their sql configuration was breaking PyMySQL3.
Thanks for your reponse though. Hopefully not many other people have this issue because switching hosting companies isn't always the best answer =O

Related

In a Flask application that is using SQLAlchemy, is it ok to permanently put `session.rollback` at the beginning of the app?

I'm new to Flask and web development in general. I have a Flask web-application that is using SQLAlchemy, is it ok to put session.rollback at the beginning of the app in order to keep it running even after a transaction fails?
I had a problem with my website when it stopped working after I was attempting to delete records of one table. The error log showed that the deletion failed due to entries in another table still referencing these records as their foreign key. The error log suggested using session.rollback to rollback this change, so I put it at the beginning of my app just after binding my database and creating the session and my website worked. This gave me the hint to leave that line there. Is my move right, safe and ok? Can anyone tell me what is the correct thing to do if this is somewhat endangering the functionality or logic of my website by any chance?
I'd say by that you are by definition cargo cult coding and should try to determine why you're finding these errors in the first place instead of just including a bit of code for a reason you don't understand.
The problem you're describing is the result of using foreign keys to ensure data integrity in your database. Typically SQLAlchemy will nullify all of the depending foreign keys, but since I don't know anything about your set up I can't explain why it wasn't. It is perhaps a difference between databases.
One massive problem with putting the rollback at the beginning of a route (or the entire global app) is that you might rollback data which you didn't want to. You haven't provided an MVCE so no one can really help you debug your problem.
Cargo cult coding in circumstances like this is understandable, but it's never a good practice. To solve this problem, investigate the cascades in SQLAlchemy. Also, fire up your actual SQL db interface and look at the data's structure, and set SQLALCHEMY_ECHO = 1 in your config file to see what's actually getting emitted.
Good luck!
You should not use the rollback at the beginning but when a database operation fails.
The error is due to an integrity condition in your database. Some rows in your table are being referenced by another table. So, you have to remove referencing rows first.

InterfaceError: Error binding Parameter 5...Django JWT token (django request token tool)

I am trying to set up a "one time use" link creating system with this tool:
https://github.com/yunojuno/django-request-token
I have followed the instructions on the installation and implementation. Now the implementation says that I should create a Requesttoken in the admin interface or with some other method.
When I go to the admin interface and when I go to add the token, I fill out the scope field which is the only one required and click save. This is where I get the
InterfaceError:r: Error binding Parameter 5 - probably unsupported type
And the error seems to happen at this line of code:
super(RequestToken, self).save(*args, **kwargs)
Now I will include the models.py file:
https://github.com/yunojuno/django-request-token/blob/master/request_token/models.py
This is the file which contains the line of code which is causing the error.
I am really stuck on this and I hope someone will know how to fix it.
If you dont know how to fix the problem maybe you know some tool which does a simillar thing as this one.
Thanks in advance
I have fixed the issue I had so I wanted to provide the answer on how I did it so if anyone encounters this InterfaceErrror, maybe you can try this.
Basically Django's default database is SQLite3 but this app requires PostgreSQL which I somehow overlooked, so if you are encountering the "Error binding Parameter 5", maybe you can try changing your database and hopefully that will fix the error as it did for me.

Postgres data loss

We have an app hosted on Heroku. Recently, I witnessed data being lost from the postgres database. The app is made with django, and there are news articles. So I edited the title of an article and saved it. I could see that changes were saved in the django admin and on the site the corrected title appeared. But after a while, the old version of the title reappeared on the site. So I edited the title for the second time, and the same thing happened again. This time, it took sometime between 1 and 30 minutes for the old version to reappear.
I am completely confused to what might be happening here. There is no indication of any kind of error in the logs.
I asked Heroku support for assistance, but without being able to reproduce the error, they couldn't really do much.
This phenomenon happened twice. I'd like to understand it so if anyone has a theory, please share it.
Thanks!

Django/python and Apache Solr: pysolr or solrpy?

brand new on this forum and this is my first post!
At work we're starting a project which uses Apache Solr and i'm in charge of the frontend system (Django-based).
Our solr database isn't related to any other db engine nor to any models' class, so Haystack isn't good for us (since its strictly related to the models).
I was looking at http://code.google.com/p/pysolr/ and http://code.google.com/p/solrpy/
Basically, they're similar. I like more solrpy, since it uses POST requests and we can mask our users queries, but this makes its paginator harder to use (i guess..).
Other side, pysolr, thanks to the GET method, performs better (lower query timing), but so far i couldn't execute a query without getting a badrequest error.
Before choosing one, i wanted to ask the community any opinion. Users need to do only searches, our data is handled by a java process, no other db is used (except for storing user informations), and we need to use all solr features (faceting, highlight, word stopping, analyzers...).
What will you choose? And why? Any good code example you can point me at? I was looking throu the haystack source to see how they did implement all...
Thanks all!
We have used 'solrpy', but encountered some problems with it.
Sunburnt is actually an interesting API:
https://github.com/tow/sunburnt/
Actively developed, and easy to use. Unfortunately it introduces some additional dependencies.

How do I properly unit test a Django session?

The behavior of Django sessions changes between "standard" views code and test code, making it unclear how test code is written for sessions. Googling this yields two relevant discussions about this issue:
Easier manipulation of sessions by
test client
test.Client.session.save() raises
error for anonymous users
I'm confused because both tickets have different ways of dealing with this problem and they were both Accepted. I assume this means they were patched and the behavior is now different. I also don't know to which versions these patches would pertain.
If I'm writing a unit test in Django 1.0, how would I set up my session store for sessions to work as they do in the browser?
I don't quite understand what do you mean by saying the behavior changes between "standard" view and "test" code, maybe you should elaborate on that.
but regarding how to test the session, I do think there are approaches.
you have to understand how django session works, read the unit test for the session package you used in your application. this is regarding understand how server side works.
you probably need to capture a few conversations between browser and server( using FIREBUG for example )
so the issue for you looks like that you are not passing session_id you get when you log in back to server when you talk to server. like put it in (POST,GET,COOKIES I don't quite remember that ).
The important thing here is understand how session works in HTTP, once you get that, you definitely have a clear idea about what is happening there, and make explainations accordingly.

Categories