Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup_config() got an unexpected keyword argument 'url' #45

Closed
kennym opened this issue Apr 15, 2020 · 7 comments
Closed

setup_config() got an unexpected keyword argument 'url' #45

kennym opened this issue Apr 15, 2020 · 7 comments

Comments

@kennym
Copy link

kennym commented Apr 15, 2020

Python version: 3.7.7

I'm using the same code as in the README, but I'm getting the following error when running it:

Traceback (most recent call last):
  File "main.py", line 14, in <module>
    pywebcopy.config.setup_config(**kwargs)
TypeError: setup_config() got an unexpected keyword argument 'url'

This is the code:

import pywebcopy

# Rest of the code is as usual
kwargs = {
    'url': 'XXX',
    'project_folder': '/Users/kennymeyer/Projects/zyx',
    'project_name': 'zyx',
    'bypass_robots': True,
}
pywebcopy.config.setup_config(**kwargs)
pywebcopy.save_webpage(**kwargs)

What am I doing wrong?

@KuroiKuro
Copy link

Hi, I believe 'url' should be 'project_url'

@kennym
Copy link
Author

kennym commented Apr 15, 2020

When I do that, I get:

Traceback (most recent call last):
  File "main.py", line 15, in <module>
    pywebcopy.save_webpage(**kwargs)
TypeError: save_webpage() missing 1 required positional argument: 'url'

@rajatomar788
Copy link
Owner

Try it out simply as documented.

from pywebcopy import save_webpage

save_webpage(
 'http://example-site.com/',
 project_folder='path/to/downloads',
 project_name='xyz', 
 bypass_robots=True
)

@dansaavedra
Copy link

When I do that, I get:

Traceback (most recent call last):
  File "main.py", line 15, in <module>
    pywebcopy.save_webpage(**kwargs)
TypeError: save_webpage() missing 1 required positional argument: 'url'

I was able to get it to work by using project_url for setup_config and then changing it back to url for save_webpage. Something like this:

import pywebcopy

# Rest of the code is as usual
kwargs = {
    'project_url': 'XXX',
    'project_folder': '/Users/kennymeyer/Projects/zyx',
    'project_name': 'zyx',
    'bypass_robots': True,
}

kwargs2 = {
    'url': 'XXX',
    'project_folder': '/Users/kennymeyer/Projects/zyx',
    'project_name': 'zyx',
    'bypass_robots': True,
}
pywebcopy.config.setup_config(**kwargs)
pywebcopy.save_webpage(**kwargs2)

@rajatomar788
Copy link
Owner

rajatomar788 commented Apr 17, 2020

Ok cool.
I still don't understand, why you can't keep it simple? But your implementation is ok too, so no worries.

from pywebcopy import save_webpage

save_webpage(
 'http://example-site.com/',
 project_folder='path/to/downloads',
 project_name='xyz', 
 bypass_robots=True
)

The function save_webpage automatically changes the global config and does the job without your need to manually configure it.

@kennym
Copy link
Author

kennym commented Apr 17, 2020

@rajatomar788 I need to set custom cookies. How would I do that with your approach? Also, can you fix your README example and/or fix the API?

@rajatomar788
Copy link
Owner

If you need to set cookies then just import the SESSION variable from pywebcopy then configure it and continue as above.

import requests 
from pywebcopy import SESSION

cookie_obj = requests.cookies.create_cookie(domain='www.domain.com',name='COOKIE_NAME',value='the cookie works')
SESSION.cookies.set_cookie(cookie_obj)

# rest of the code as above... 

@kennym kennym closed this as completed Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants