User talk:Didicodes/Sandbox/API:Account creation

About this board

SSethi (WMF) (talkcontribs)

Neat work! Thanks a lot for working on this! Here are a few suggestions:

Didicodes (talkcontribs)

Thanks for the feedback. I am done with 1 and 3, I am currently working on number 2.

I have a question about number 2: To generate the API token would I have to use a GET request for that?

Didicodes (talkcontribs)

I am done. Please Review

Didicodes (talkcontribs)

For `account_creation.py` and `account_creation_for_someone_else.py` (this file name could be a bit shorter), two points:

  • I have already changed the file names but if that does not still work for you. Here is another suggestion: `create_account_self.py` and `create_account_other.py`
SSethi (WMF) (talkcontribs)

It is coming along well! Neat! Few minor picks most of them are code related:

  • For filenames how about we name them as `create_my_account.py` and `create_a_user_account.py`.
  • Did you try running your code? It is giving me the following error:

The following parameter was found in the query string, but must be in the POST body: createtoken`. It looks you are using get request format; it should be rather post. Check the format for sending a post request here: http://docs.python-requests.org/en/master/user/quickstart/. Same comment applies for second file as well.

  • I am still getting formatting errors when I run your code via Pylint. For example if you are using Python3 then print statement needs to be wrapped in parenthesis and there are 2-3 similar errors too.

In the additional notes section, only the point about disabling the API is for MediaWiki site administrators and extension developers. The first and the second point can be combined into one.

How about you re-take a look at the changes and then may be consider sending a pull request for the code you've been working on to https://github.com/srish/MediaWiki_Action_API_Code_Samples?

Let me know if anything in here isn't clear to you! Happy to answer :-)

Didicodes (talkcontribs)

okay. Working on it now. I would ask questions if I get confused

Didicodes (talkcontribs)

About the codes, Yes I actually thought that was how it was suppose to be. I am saying this because when I clicked on this link https://en.wikipedia.org/w/api.php?action=createaccount&createreturnurl=http://example.com/&createtoken=29590a3037d325be70b93fb8258ed29257448cfb%2B%5C&username=Bob&password=ExamplePassword&retype=ExamplePassword&email=bob%40example.com&realname=Robert%20Example to run the api it actually produces the same error too.I have always wanted to ask if that is how it is suppose to be! Apparently it is not, does this mean changes would have to be made to this link too?

Didicodes (talkcontribs)

I checked out the format for sending a post request here: http://docs.python-requests.org/en/master/user/quickstart/ and modified the codes(It is now working well in terms of the post request but it is showing another error). I pasted the codes on pastebin here: https://pastebin.com/4SxJBByx

and this is the error:

{"error":{"code":"badtoken","info":"Invalid CSRF token.","*":"See https://www.mediawiki.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes."},"servedby":"mw2135"}

So I wrote codes that generated the CSRF token. link here: https://pastebin.com/yKXppxCd

but I am having troubles integrating both of them together so that the code works well without any errors.

SSethi (WMF) (talkcontribs)

@Didicodes Yes, I can speculate why you are running into these errors. A few helpful tips:

Happy to answer any follow-up questions or help understand any piece in the clientlogin.py code that is not clear to you!

Didicodes (talkcontribs)

Hello SSethi so I have been working on the codes again using this link you recommended https://pythonspot.com/flask-web-forms/. I learned alot from it about flask, I have not used it before so it was an amazing experience. I also copied the the login.py codes form your github and got it to run(after I learnt how to create templates for python and use flask) but it suceesful ret and post requests runs it produces this error: key error `client login`. Is there a reason for this or is it because I didnt go through the right process. My own code also produces key error: `createaccount`

Didicodes (talkcontribs)

Also, I got it to work on my mediawiki core. This is the link to the codes https://pastebin.com/mw4j6Rq1

(Note: This only works on mediawikicore localhost)

Didicodes (talkcontribs)

It seems you've been really busy.

Looking forward to hearing back from you :)

SSethi (WMF) (talkcontribs)

@Didicodes So, good that you got it working on MediaWiki core locally. But, ideally, we want to write a script that could communicate with either test Wikipedia, MediaWiki or English Wikipedia over HTTP without having to download the code locally. Also for account creation, if you want to use the login code, then the example you want to refer is that of clientlogin.py in the Github repository and not login.py. Because the procedure we need to follow for account creation is this -- we need to obtain information for specific fields from the user, make a post request, and provide a return URL so that when the request finishes your program can send the browser somewhere. Does that make sense?

Didicodes (talkcontribs)

okay. I actually used the cleintlogin.py codes and when I ran the the codes it produced this error. **Key Error `clientlogin`. I wanted to know why this happened? because I was also able to work on the Create account Api following cleintlogin.py and it produced the same error.

Reply to "Feedback 1.0"
There are no older topics