Code Monkey home page Code Monkey logo

py3-pinterest's Introduction

py3-pinterest

License: MIT

Unofficial Pinterest API implemented in python 3 that can do all Pinterest tasks like comment, pin, repin, follow, unfollow, and more.

It is implemented by directly calling the pinterest servers, mimicking an actual browser, so you don't need pinterest API key.

If you see any issues, or find bugs feel free to report them here on the github repo.

Community guides

Get started with pinterest automation

Automated posting to Pinterest (in Russian)

Install using pip

pip install py3-pinterest

NOTE: for each of the functionalities listed below there is a working example under the project root.

Create new instance of the API

pinterest = Pinterest(email='your email goes here', password='password goes here', username='look in pinterest url', cred_root='cred root dir')

cred_root is the dir (automatically created if missing) that will store some cookies and sessions, so you don't need to login before each request. Make sure you specify a path with read/write permissions.

Proxies example:

proxies = {"http":"http://username:password@proxy_ip:proxy_port"}
Pinterest(email='emai', password='pass', username='name', cred_root='cred_root', proxies=proxies)

The following features are currently supported

Login/Logout

NOTE: Pinterest integrated google recaptcha. This means we have to use web driver to login. For that reason you must have chrome installed on you computer, in order for the login to work.

If you want to use many accounts, you should associate proxy with each one of them and login only with that proxy

pinterest.login(proxy='ip_address:port')

Login will store auth cookies for later use. These cookies are usually valid for ~15 days, then you will start getting 403 and 401 errors, which means you need to call login again.

Login

Login is required to permit actions to the Pinterest servers. Login will store auth cookies for later use. These cookies are usually valid for ~15 days, then you will start getting 403 and 401 errors, which means you need to call login again.

pinterest.login()

pinterest.logout()

Load profile

You can load profile for currently logged in user or any user specified by username.

user_profile = pinterest.get_user_overview()

Board and pin management

Get all boards of user:

boards = pinterest.boards(username='username')

List all pins in board

pins = pinterest.board_feed(board_id=board_id)

If username is left blank, current logged in user will be used.

Delete pin

pinterest.delete_pin(pin_id='pin_id')

Repin

pinterest.repin(board_id='board_id', pin_id='pin_id')

Get ID of created pin, section, or board

All functions return the post/get data from the request. If you dig a little deeper by going myrequest.content you get the actual HTML response, which can then be turned into a dict by using JSON.

Example:

import json

pin_response = upload_pin(board_id='',
             image_path='test.png',
             description='TESTING PIN FUNCTIONALITY WITH ID FETCHING',
             title='Foobar Barfood',
             section_id=None,
             link='')

response_data = json.loads(pin_response.content)

Some helpful notes on the response: Everything is stored inside the "resource_response" key. You can use that and grab all sorts of data like so:

# This is how you would access this information when creating a pin

id = response_data["resource_response"]["data"]["id"]
board_id = response_data["resource_response"]["data"]["board"]["id"]
section_id = response_data["resource_response"]["data"]["section"]["id"]
pinner_username = response_data["resource_response"]["data"]["pinner"]["username"]
pinner_id = response_data["resource_response"]["data"]["pinner"]["id"]

# If you wanted to access this information in a different circumstance,
# keep in mind that whatever you are creating should be the first level under "data"
# I.e, I created a board, and I want to get the board ID. It would now be:

board_id = response_data["resource_response"]["data"]["id"]

Get pinnable images

A pinterest feature they use to pin from websites

pinterest.get_pinnable_images(url='https://www.tumblr.com/search/food')

Pin

Pin image by web url:

pinterest.pin(board_id=board_id, image_url=image_url, description=description, title=title)

Pin image from local file:

pinterest.upload_pin(board_id=board_id, section_id=section_id, image_file=image_path, description=description, title=title, link=link)

Get home feed pins

home_feed_batch = pinterest.home_feed()

Get board recommendations (this is the 'more ideas' api)

rec_batch = pinterest.board_recommendations(board_id=board_id)

Get pin information by id

pinterest.load_pin(pin_id='pin_id')

Board Section support

pinterest.create_board_section(board_id=board_id, section_name=section_name) pinterest.delete_board_section(section_id=section_id) pinterest.get_board_sections(board_id=board_id)

You can also pin and repin to sections.

Follow/Unfollow

Follow

pinterest.follow_user(user_id='target_user_id', username='target_username')

Follow limit is 300 per day, after that they might place you on a watch list

Unfollow

pinterest.unfollow_user(user_id='target_user_id', username='target_username')

Unfollow limit is 350 per day, after that they might place you on a watch list

Get following

following_batch = pinterest.get_following(username='some_user')

If username is not provided current user will be used

Get followers

followers_batch=pinterest.get_user_followers(username='some_user')

If username is not provided current user will be used

Follow board

pinterest.follow_board(board_id=board_id)

Unfollow board

pinterest.unfollow_board(board_id=board_id)

Search

search_batch = pinterest.search(scope='boards', query='food')

Current pinterest scopes are: pins, buyable_pins, my_pins, videos, boards

Visual Search

  pin_data = pinterest.load_pin(pin_id='pin_id')
  search_batch = pinterest.visual_search(pin_data, x=10, y=50, w=100, h=100)

User interactions

Invite to board

pinterest.invite(board_id=board_id, user_id=target_user_id)

Delete board invite

pinterest.delete_invite(board_id=board_id, invited_user_id=target_user_id)

Get board invites

invites_batch = pinterest.get_board_invites(board_id=board_id)

Comment

pinterest.comment(pin_id=pin_id, text=comment_text)

Delete comment

pinterest.delete_comment(pin_id=pin_id, comment_id=comment_id)

Get Pin comments

pinterest.get_comments(pin_id='pin_id')

Send personal message

pinterest.send_message(conversation_id=conversation_id, pin_id="(pin_id)", message="hey")

Access to type suggestions you see in the search input

pinterest.type_ahead(term='apple')

py3-pinterest's People

Contributors

alglez avatar anonymustard avatar bahrmichaelj avatar bstoilov avatar capofweird avatar elmissouri16 avatar fratamico avatar gmanicus avatar imgvoid avatar kruvatz avatar magicaltoast avatar marcosfelt avatar mfhassan22 avatar rkuttruff avatar veempees avatar victorviro avatar vladradishevsky avatar vriadlee avatar vtni avatar yaonur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

py3-pinterest's Issues

Description of Documentation of the Pin Data?

Hi there! Thanks for the work at first.
I just have a question about the data. The pin data returned have "repin count" field and there is an "aggregated data" column where there is "saves" count. What's the difference? In Pinterest's instruction (https://help.pinterest.com/en/business/article/pin-stats), a save equals a repin. However, the repin count and the saves count is drastically different for each pin I retrieved.

And the aggregated stats have a key called "done", which is also confusing?

Thanks in advance.

Feature Request Placeholder for next Release

I have been asked to introduce some things to the client, via email or PM, so I decided to created this issue to track any feature requests and perhaps vote on some of them.
Leave a comment below if you wan't something included.

  • Simple Desktop UI
  • Pin Scheduler
  • Cloud hosted version of the client (with web ui)
  • Support for business accounts

"Response [400]" (Bad Request) on initiating conversation

Hello and Greetings Mr. Borislav Stoilov.

I have been trying to initiate a conversation but I get a "Response [400]" which means Bad Request. Other things such as get_user_overview() or search() or pin() work perfectly fine.

My code is as following:

from py3pin.Pinterest import Pinterest

pinterest = Pinterest(email=my_email, password=my_password, username=my_username, cred_root=my_cred_root)
result = pinterest.initiate_conversation(user_ids=my_user_id, message='testing...')

print(result)

Output:

<Response [400]>

Any idea what might be causing this issue?

Thank you. :)

404 Client Error: on get_board_sections

Hi All,
Today I started to have issues when I try to get the sections from a board.

LOG:

    sections = pinterest.get_board_sections(board_id=target_board['id'])
  File "I:\myPInt\python\py3-pinterest-master.vCN\py3pin\Pinterest.py", line 618, in get_board_sections
    response = self.get(url=url).json()
  File "I:\myPInt\python\py3-pinterest-master.vCN\py3pin\Pinterest.py", line 103, in get
    return self.request('GET', url=url)
  File "I:\myPInt\python\py3-pinterest-master.vCN\py3pin\Pinterest.py", line 98, in request
    response.raise_for_status()
  File "C:\Users\Administrador\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://www.pinterest.com/resource/BoardSectionsResource/get//?source_url=%2F&data=%7B%22options%22%3A%20%7B%22isPrefetch%22%3A%20false%2C%20%22board_id%22%3A%20%22433330864085824355%22%2C%20%22page_size%22%3A%2050%2C%20%22redux_normalize_feed%22%3A%20true%7D%2C%20%22context%22%3A%20null%7D&_=1586121571802

Any idea how I can fix it?
Thanks,
Kristy

Pin function strips whitespace?

Hi there! I am trying to work with your repository from a couple of days but I am having some trouble with the pin titles.

I am using bs4 to get the title of a webpage to use as the pin title. The variable displays correctly when printed, but as soon as I pass it to the pin function all of the white spaces are removed when I look at the board on Pinterest.

Any idea why is this happening? Can you look at my code and help me figure it out?

Issue while creating new pin

Hi,
First of all, thank you for all the hard work you've put in.

I am trying to create a new pin in an already created board. getting the following error.

Environment:
OS: Linux / 64bit
Python : 3.7

Forbidden for url: https://www.pinterest.com/resource/PinResource/create/

Traceback (most recent call last):
File "modules/destination/pin_terest.py", line 24, in
abc = pin()
File "modules/destination/pin_terest.py", line 21, in pin
return pinterest.pin(board_id=board_id, image_url=image_url, description=description, title=title, link=link)
File "/home/g/anaconda3/envs/pinterest_bot/lib/python3.7/site-packages/py3pin/Pinterest.py", line 321, in pin
return self.post(url=PIN_RESOURCE_CREATE, data=data).json()
File "/home/g/anaconda3/envs/pinterest_bot/lib/python3.7/site-packages/py3pin/Pinterest.py", line 104, in post
return self.request('POST', url=url, data=data, files=files)
File "/home/g/anaconda3/envs/pinterest_bot/lib/python3.7/site-packages/py3pin/Pinterest.py", line 96, in request
response.raise_for_status()
File "/home/g/anaconda3/envs/pinterest_bot/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://www.pinterest.com/resource/PinResource/create/

upload_pin freeze

I try to make software for uploading 1-3 pins every couple of minutes to Pinterest.
At the beginning I authenticate to Pinterest, upload 1-3 pins and that work correctly.
After sleep of couple minutes when script try to upload other 1-3 pins first call to upload_pin freeze and never return from call.

429 Client Error: Too Many Requests for url

Hi,

Getting close to the completion of a project using the py3-pinterest library. Forgot to disable a function that was creating a test pin, and I ended up creating a pin every time a ran a test. Not too big a deal. Created like 30 pins over a few hours.

Anyway, it was made evident that I forgot that function when I started getting the 429 client error. I see there is there is a rate limit in the Pinterest API. It's 10 actions per hour per unique user for apps that haven't been approved.

I take it py3-pinterest is limiting to 10 per hour? Is there anything I can do to keep the issue from happening when I finish the project? I'd like to avoid getting rate-limited if possible. I expect anywhere from 1-10 per hour for now. More if my project ends up getting used a lot.

Pinterest Private proxy login ?

My English is bad :)

I manage multiple pinterest accounts. I want to login using private proxy. Private proxy authentication need. If you provide a sample code blog, I'll solve it immediately.

Create Boards Unauthorized for url error ?

Hi,
No matter how much I try, I can't create a board. I get the same error with several different users.

Python code:

from py3pin.Pinterest import Pinterest
import random,os,pickle


username = 'lum-customer-hl_18949a2b-zone-********'
password = 'passwords'
port = 22225
session_id = random.random()
super_proxy_url = ('http://%s-session-%s:%[email protected]:%d' %
    (username, session_id, password, port))


proxies = {
  "http": super_proxy_url,
  "https": super_proxy_url
}

pinterest = Pinterest(email='[email protected]',
                      password='Judgenie!5145',
                      proxies=proxies,
                      username='userurl',
                      cred_root='cred_root')

logged_in = pinterest.login

boards = pinterest.boards()

for i in boards:
    print(i['name'])
    print(i['id'])

boardadd = pinterest.create_board('Design', 'Design')

Error code:
Traceback (most recent call last): File "C:\Users\****\Desktop\pint\pinterest1.py", line 34, in <module> boardadd = pinterest.create_board('Design', 'Design') File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py3pin\Pinterest.py", line 177, in create_board return self.post(url=CREATE_BOARD_RESOURCE, data=data) File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py3pin\Pinterest.py", line 110, in post return self.request('POST', url=url, data=data, files=files, extra_headers=headers) File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py3pin\Pinterest.py", line 102, in request response.raise_for_status() File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://www.pinterest.com/resource/BoardResource/create/

Pin issue description & link

Hi!
Thanks for the workaround.
I got an issue when uploading pin
p.upload_pin(board_id='1111', image_file="pathtoimage/img.jpg", description='blabla #test #test2', link='linktohtmlpage', title='title', section_id=None)
Everything is ok, except that description is text from link, and provided description is ignored. Any thoughts?

Updated

I checked p.pin method with image_url the same here

Limits for Search Results

Hi there. Just wondering what is the limits for the results returned by searching pins with keywords. I've tried to remove the max_iteration in the example code and it could only give me 1076 results no matter what query I put in. Thus, is this API only retrieves the top 1076 results for searching?

pinterest.login() - error

I am receiving the following error while executing login function

`---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
in
----> 1 pinterest.login()

C:\python\lib\site-packages\py3pin\Pinterest.py in login(self)
116
117 data = self.req_builder.buildPost(options=options, source_url='/login/?referrer=home_page')
--> 118 return self.post(url=CREATE_USER_SESSION, data=data)
119
120 def get_user_overview(self, username=None):

C:\python\lib\site-packages\py3pin\Pinterest.py in post(self, url, data, files, headers)
104
105 def post(self, url, data=None, files=None, headers=None):
--> 106 return self.request('POST', url=url, data=data, files=files, extra_headers=headers)
107
108 def login(self):

C:\python\lib\site-packages\py3pin\Pinterest.py in request(self, method, url, data, files, extra_headers)
96
97 response = self.http.request(method, url, data=data, headers=headers, files=files, proxies=self.proxies)
---> 98 response.raise_for_status()
99 self.registry.update(Registry.Key.COOKIES, response.cookies)
100 return response

C:\python\lib\site-packages\requests\models.py in raise_for_status(self)
938
939 if http_error_msg:
--> 940 raise HTTPError(http_error_msg, response=self)
941
942 def close(self):

HTTPError: 401 Client Error: Unauthorized for url: https://www.pinterest.com/resource/UserSessionResource/create/`

board follow and user follow NOT working

Hi I have tried out the example python scripts.
Although I could successfully logged in and pull up board ids and user ids from the script,
when the script run the "follow" methods, it will ends up with exception errors.

Does anyone successfully use the follow method? maybe Pinterest has changed their API?

Pin Help

How can i upload image from my machine directory ?

Create Board

Hi again,

It seems the only thing this library is missing is a create_board function. Is there a limitation that doesn't allow this functionality?

Thanks

email error message

Getting the following error when trying to create new instance by running the following:
pinterest = Pinterest(email='your email goes here', password='password goes here', username='look in pinterest url', cred_root='cred root dir')

error message: TypeError: init() got an unexpected keyword argument 'email'

Not sure what is going wrong here (of course I am replacing the value with my own email, password etc.)

pin of video?

hello

If I will like post a pin of youtube video?

reggards

handle board sections

Hi, Is it possible to improve this project to also handle the board sections?

If it is already supported, can you let me know how to work with them?

Thanks a lot for your great work!
Kristy

Traceback issue

Hi,
I have a issue with the download_board_image.py, when i type the command:
python3 download_board_images.py
he show me the error ::
Traceback (most recent call last):
File "download_board_images.py", line 39, in
url = pin['image']
KeyError: 'image'

I am dont understand what is the problem ...

Thank in advance to your help

feature request: Managing several accounts with the same credentials.

Hi!

First of all - thanks a lot for porting pinterest client to python3, i really appreciate it.

You probably know that pinterest allows to create a business account with same credentials as a personal account. Basically, we can switch between two accounts in pinterst UI (screenshot attached)
more info about business accs.: https://help.pinterest.com/en/business/article/get-a-business-account
![pin-accs]

(https://user-images.githubusercontent.com/29484065/65815830-fc280480-e1fc-11e9-8934-ca10349e9161.png)

I've noticed that functionality of py3-client is limited to personal account only, as I'm getting 403/404 errors when trying create something under business account.

So. my question (feature request) is: Is it possible to add support for managing several account under the same credentials?

And again, thanks for all your efforts!

404 Client Error

Hello,

Whenever I try to send a pin with pin() I get an error:

requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://www.pinterest.com/resource/PinResource/create/

How can I fix it?

401 Client Error after the first successful repin

Hello !
I have this small program , it's able to repin once, then it send error 401. Any help or suggestion would be appreciated as i m stuck at this point. So far i tried :

  • Delete cred root
  • Checked if i can login in chrome (yes i can)
  • Adding delay between actions

Thank you

import random
import time
import os

from py3pin.Pinterest import Pinterest

pinterest = Pinterest(email='******',
                      password='*****',
                      username='*******',
                      cred_root='cred_root')


#logged_in = pinterest.login()

boards = pinterest.boards(username='*********')

for board in boards:
    
    board_id = board['id']
    board_name = board['name']
    
    print("Looking for pins for " + board_name)
    
    search_batch = pinterest.search(scope='pins', query=board_name)
    
    time.sleep(random.randint(13,20))
    
    number_pin = random.randint(0,len(search_batch))
    
    pin_id = search_batch[number_pin]['id']
    
    name_pin = search_batch[number_pin]['domain']
    
    print("Repinning pin from " + name_pin)
    
    pinterest.repin(board_id=board_id,
                    pin_id=pin_id)
    
    time.sleep(random.randint(3,7))

this is the error message i get :

Looking for pins for ********
Repinning pin from ********
Looking for pins for ********
Repinning pin from ********
Traceback (most recent call last):
  File "C:\****\pinterest\testrun.py", line 37, in <module>
    pin_id=pin_id)
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packa
ges\py3pin\Pinterest.py", line 286, in repin
    return self.post(url=REPIN_RESOURCE_CREATE, data=data)
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packa
ges\py3pin\Pinterest.py", line 106, in post
    return self.request('POST', url=url, data=data, files=files, extra_headers=h
eaders)
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packa
ges\py3pin\Pinterest.py", line 98, in request
    response.raise_for_status()
  File "C:\Users\****\AppData\Local\Programs\Python\Python37-32\lib\site-packa
ges\requests\models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://w
ww.pinterest.com/resource/RepinResource/create/

Exception: Wrong credentials

Hi, thanks for maintaining this module!

I can't seem to create a pin without getting a wrong credential error. I've cross referenced my credentials several time so I am positive they are correct. I have copy and pasted them straight from Pinterest to make sure.

from py3pin.Pinterest import Pinterest

pinterest = Pinterest(email=email,
                      password=password,
                      username=username,
                      cred_root=cred_root)

# get boards (works fine)
board_batch = pinterest.boards() 

# example board ID
pinterest.pin(board_id='845258473083496787', image_url='https://www.321howto.com/wp-content/uploads/2017/11/Perfect-Garden-2018.jpg', description='A truly perfect description!', title='Great title', link='www.google.com')

Error code:

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in login(self)
    116         try:
--> 117             response = self.post(url=CREATE_USER_SESSION, data=data)
    118             response = response.json()

~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in post(self, url, data, files)
    103     def post(self, url, data=None, files=None):
--> 104         return self.request('POST', url=url, data=data, files=files)
    105 

~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in request(self, method, url, data, files)
     95 
---> 96         response.raise_for_status()
     97         self.registry.update(Registry.Key.COOKIES, response.cookies)

~/anaconda3/lib/python3.6/site-packages/requests/models.py in raise_for_status(self)
    939         if http_error_msg:
--> 940             raise HTTPError(http_error_msg, response=self)
    941 

HTTPError: 429 Client Error: Too Many Requests for url: https://www.pinterest.com/resource/UserSessionResource/create/

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in login(self)
    116         try:
--> 117             response = self.post(url=CREATE_USER_SESSION, data=data)
    118             response = response.json()

~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in post(self, url, data, files)
    103     def post(self, url, data=None, files=None):
--> 104         return self.request('POST', url=url, data=data, files=files)
    105 

~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in request(self, method, url, data, files)
     92         if response.status_code == 401:
---> 93             self.login()
     94             response = self.http.request(method, url, data=data, headers=headers, files=files, proxies=self.proxies)

~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in login(self)
    120             self.login_failed = True
--> 121             raise Exception("Wrong credentials")
    122         return response

Exception: Wrong credentials

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in login(self)
    116         try:
--> 117             response = self.post(url=CREATE_USER_SESSION, data=data)
    118             response = response.json()

~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in post(self, url, data, files)
    103     def post(self, url, data=None, files=None):
--> 104         return self.request('POST', url=url, data=data, files=files)
    105 

~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in request(self, method, url, data, files)
     92         if response.status_code == 401:
---> 93             self.login()
     94             response = self.http.request(method, url, data=data, headers=headers, files=files, proxies=self.proxies)

~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in login(self)
    120             self.login_failed = True
--> 121             raise Exception("Wrong credentials")
    122         return response

Exception: Wrong credentials

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
<ipython-input-2-b792fad0d3c1> in <module>
      8 
      9 # make pin
---> 10 pinterest.pin(board_id='845258473083496787', image_url='https://www.321howto.com/wp-content/uploads/2017/11/Perfect-Garden-2018.jpg', description='A truly perfect description!', title='Great title', link='www.google.com')

~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in pin(self, board_id, image_url, description, link, title)
    319         data = self.req_builder.buildPost(options=options, source_url=source_url)
    320 
--> 321         return self.post(url=PIN_RESOURCE_CREATE, data=data).json()
    322 
    323     def repin(self, board_id, pin_id):

~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in post(self, url, data, files)
    102 
    103     def post(self, url, data=None, files=None):
--> 104         return self.request('POST', url=url, data=data, files=files)
    105 
    106     def login(self):

~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in request(self, method, url, data, files)
     91         response = self.http.request(method, url, data=data, headers=headers, files=files, proxies=self.proxies)
     92         if response.status_code == 401:
---> 93             self.login()
     94             response = self.http.request(method, url, data=data, headers=headers, files=files, proxies=self.proxies)
     95 

~/anaconda3/lib/python3.6/site-packages/py3pin/Pinterest.py in login(self)
    119         except Exception as e:
    120             self.login_failed = True
--> 121             raise Exception("Wrong credentials")
    122         return response
    123 

Exception: Wrong credentials

Looks like there's a 429 error in the mix which is odd as this is my only attempted request...

Search returns quite small number of results for Multiple Word Queries

Hello again Mr. Stoilov.

I am stuck in yet another issue involving the function Pinterest.search() in Pinterest.py starting from Line 368. I have tried with both branches, the master branch as well as the board-section-refactor branch.

Single Word Query
boards_query_result = pinterest.search(scope='boards', query='hello')

returns 250 boards, which is all good. The result is the same as the one returned by the UI.
https://www.pinterest.com/search/boards/?q=hello&rs=typed&term_meta[]=hello%7Ctyped

But in case of double word query:

Double Word Query
boards_query_result = pinterest.search(scope='boards', query='hello world')

returns only 23 boards. Whereas, the expected results should have been:
https://www.pinterest.de/search/boards/?q=hello%20world&rs=typed&term_meta[]=hello%7Ctyped&term_meta[]=world%7Ctyped

Any idea what might be the issue here? Or what might I be doing wrong this time ๐Ÿ˜„

Cheers and as always your help is very much appreciated. Thank you.

Better way of handling the authorization tokens

Currently a registry is used to store the cookies and some headers.

This is hard to read and maintain.

A much simpler solution is to keep cookies in file and read them like plain string.

    def _load_headers(self):
        cookies = self.registry.get(Registry.Key.COOKIES)
        csrftoken = ''
        cookie_str = ''
        for c in cookies:
            if c.name == 'csrftoken':
                csrftoken = c.value
            cookie_str += c.name + '=' + c.value + '; '
        cookie_str = cookie_str.strip()

        headers = {
            'cookie': cookie_str,
            'x-csrftoken': csrftoken,
            'user-agent': AGENT_STRING
        }

        return headers

this is all the data we need to make requests

After this change all requests can be simplified to the following structure

        options = {
        }

        data_obj = {
            'options': options,
            'context': {}
        }

        data = {
            'source_url': '/pin/{}/'.format(pin_id),
            'data': json.dumps(data_obj)
        }

        headers = self._load_headers()
        return requests.post(url=url, headers=headers, data=data)

Error retrieving followers

Traceback(most recent call last):
  File "C:\Users\owner\AppData\Local\Programs\Python\Python37\Lib\site-packages\py3pin\bath-parlor.py", line 14, in <module>
    pinterest.get_user_followers();
  File "C:\Users\owner\AppData\Local\Programs\Python\Python37\lib\site-packages\py3pin\Pinterest.py", line 258, in get_user_followers
    result = self.get(url=url).json()
  File "C:\Users\owner\AppData\Local\Programs\Python\Python37\lib\site-packages\py3pin\Pinterest.py", line 94, in get
    return self.request('GET', url=url)
  File "C:\Users\owner\AppData\Local\Programs\Python\Python37\lib\site-packages\py3pin\Pinterest.py", line 89, in request
    response.raise_for_status()
  File "C:\Users\owner\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://www.pinterest.com/_ngjs/resource/UserFollowersResource/get/?source_url=%2Finfo%40justyouandlove.com%2F_followers%2F&data=%7B%22options%22%3A%7B%22isPrefetch%22%3A%22false%22%2C%22hide_find_friends_rep%22%3A%22true%22%2C%22username%22%3A%22%22%2C%22page_size%22%3A250%2C%22bookmarks%22%3A%5Bnull%5D%7D%2C%22context%22%3A%7B%7D%7D&_=1566006664415

Process returned 1 (0x1)        execution time : 6.552 s
Press any key to continue . . .

I got this error when running
pinterest.login(); pinterest.get_user_followers();

I was using the modified example.py

Also, how can we automate pinning to a board list and tasks in a time spaced loop?

Changing User-Agent

Hi

Is it possible to change the user-agent used? On a per-account/login basis?

Thanks

Various HTTP Errors

Thank you for this script! I have tried rewriting other Pinterest libraries to be python3 compatible, but this is far more robust.

I am using this at smallish scale (testing with ~10 accounts) and have come across a few different HTTP Errors:

requests.exceptions.HTTPError: 404 Client Error: Not Found for url
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url

The credentials to the accounts are correct and have had library functions properly working before.

Are these errors happening because multiple accounts are being used by this script? Is there a way to better debug these errors on the accounts the library is failing on occasionally?

Thanks!

All Boards List limit 50 ?

Hello,

User's 111 pinterest boards has.

boards = pinterest.boards()
                print(boards)

is limited to 50

Do I have a chance to reach the whole list

Sing out account

hello, is py3-pinterest has sign out from account. if its not, could u coding it

Better Appreach of Saving The registry.dat

Hey I have a suggestion related to the path of where registry.dat should be saved currently its been saved in the folder of the lib in the pip packages folder which makes it harder to access
it will be better generated on the same directory where the python file called the login function
here on this line

self.data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), cred_root,

should be
self.data_path = os.path.join(cred_root,self.email) + os.sep

Add url to a pin

Hi,
Thank you very much for porting it to python3.
I have a feature request.
Could you add url besides image_url to pinterest.pin()?
As you might know, when user create a pin, they can link an url to it.

Regards,

Pinterest.pin error

Hello, I am facing an issue. The board ID is correct.
Traceback (most recent call last):
File "pinit.py", line 42, in
pinterest.pin(board_id='771874892324362501', section_id=None, image_url=image_file, description=description, title=title, link=link)
File "/usr/local/lib/python3.5/dist-packages/py3pin/Pinterest.py", line 270, in pin
return self.post(url=PIN_RESOURCE_CREATE, data=data)
File "/usr/local/lib/python3.5/dist-packages/py3pin/Pinterest.py", line 106, in post
return self.request('POST', url=url, data=data, files=files, extra_headers=headers)
File "/usr/local/lib/python3.5/dist-packages/py3pin/Pinterest.py", line 98, in request
response.raise_for_status()
File "/usr/local/lib/python3.5/dist-packages/requests/models.py", line 941, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://www.pinterest.com/resource/PinResource/create/

Can you help?

pinterest.pin() problem

my pin parameters like this :
pinterest.pin(board_id=627689404223348588, image_url='https://i.pinimg.com/564x/7b/ca/94/7bca948f5a5ca23a5189cfab47c157c6.jpg', description='example description', title='example title')

but i receive an error :


Traceback (most recent call last):
File "C:\Users\Fatma\Desktop\ali.py", line 20, in
pinterest.pin(board_id=627689404223348588, image_url='https://i.pinimg.com/564x/7b/ca/94/7bca948f5a5ca23a5189cfab47c157c6.jpg', description='description', title='title is here')
File "C:\python35\lib\site-packages\py3pin\Pinterest.py", line 270, in pin
return self.post(url=PIN_RESOURCE_CREATE, data=data)
File "C:\python35\lib\site-packages\py3pin\Pinterest.py", line 106, in post
return self.request('POST', url=url, data=data, files=files, extra_headers=headers)
File "C:\python35\lib\site-packages\py3pin\Pinterest.py", line 98, in request
response.raise_for_status()
File "C:\python35\lib\site-packages\requests\models.py", line 937, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://www.pinterest.com/resource/PinResource/create/

Can you help me ??

I can't make the get_section_pins works

Hi,
I tried a couple of code, but none of them are working, I get all the time the json for the board and not from the section, below is my code

boards = pinterest.boards(username=username)
for board in boards:
    target_board = board
    print(target_board['name'])
    
    sections = pinterest.get_board_sections(board_id=target_board['id'])
    for section in sections:
        print(section['title'] + '--' + section['slug'])

        section_pins = []
        section_pins = pinterest.get_section_pins(username=username, board_name=target_board['name'], section_name=section['slug'])
        with open("zz_" + target_board['name'] + " - " + section['slug'] + ".txt", "w") as file:
            json.dump(section_pins, file)

I'm doing something wrong?

Thanks,
Kristy

How to we use proxy

I see in Pinterest.py is proxies=None. But I want to use proxy, how to use it?

error on get_following

first thanks for your work
i was just testing the functions of this module and I found a bug on get_following

here is the error

File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py3pin\Pinterest.py", line 231, in get_following
self.bookmark_manager.add_bookmark(primary='following', secondary=username, bookmark=result['bookmark'])
KeyError: 'bookmark'

Create New Pin Error

I tried to make a new PIN, but an error.
this is my script

# -*- coding: utf-8 -*-
from py3pin.Pinterest import Pinterest

def test():
    username = ''
    password = ''
    email = ''

    # cred_root is the place the user sessions and cookies will be stored you should specify this to avoid permission issues
    cred_root = 'cred_root'
    pinterest = Pinterest(email=email, password=password, username=username, cred_root=cred_root)

    board_id = '854698904221395783'
    image_url = '25061712.jpg'
    description = 'description here'
    title = 'title test'
    link = 'https://pricesm.com'

    return pinterest.pin(board_id=board_id, image_url=image_url, description=description, title=title, link=link)

if __name__ == '__main__':
	test()

and this error occurred

Traceback (most recent call last):
  File "tester.py", line 22, in <module>
    test()
  File "tester.py", line 19, in test
    return pinterest.pin(board_id=board_id, image_url=image_url, description=description, title=title, link=link)
  File "/home/crabs/Documents/gameplay/py3Pinter/py3pin/Pinterest.py", line 325, in pin
    return self.post(url=PIN_RESOURCE_CREATE, data=data).json()
  File "/home/crabs/Documents/gameplay/.py3PinEnv/lib/python3.6/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

anyone can help?

unable to start the bot

i am getting this error, can anyone please help me.
Traceback (most recent call last):
File "F:\new\py3-pinterest-master\examples.py", line 10, in
pinterest.login()
File "F:\new\py3-pinterest-master\py3pin\Pinterest.py", line 118, in login
return self.post(url=CREATE_USER_SESSION, data=data)
File "F:\new\py3-pinterest-master\py3pin\Pinterest.py", line 106, in post
return self.request('POST', url=url, data=data, files=files, extra_headers=headers)
File "F:\new\py3-pinterest-master\py3pin\Pinterest.py", line 98, in request
response.raise_for_status()
File "C:\Users\12345\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\models.py", line 937, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://www.pinterest.com/resource/UserSessionResource/create/

============== RESTART: F:\new\py3-pinterest-master\examples.py ==============
Traceback (most recent call last):
File "F:\new\py3-pinterest-master\examples.py", line 10, in
pinterest.login()
File "F:\new\py3-pinterest-master\py3pin\Pinterest.py", line 118, in login
return self.post(url=CREATE_USER_SESSION, data=data)
File "F:\new\py3-pinterest-master\py3pin\Pinterest.py", line 106, in post
return self.request('POST', url=url, data=data, files=files, extra_headers=headers)
File "F:\new\py3-pinterest-master\py3pin\Pinterest.py", line 98, in request
response.raise_for_status()
File "C:\Users\12345\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\models.py", line 937, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://www.pinterest.com/resource/UserSessionResource/create/

load_pin(), doesn't work

I want use comment pin function pinterest.comment, but load_pin() has follow error:

File "\py3-pinterest\py3pin\Pinterest.py", line 330, in load_pin
return pin_data['resourceResponses'][0]['response']['data']
KeyError: 'resourceResponses'

Return Board, Section, Pin ID upon creation

Hi,

I'm currently having to scout the requests on Pinterest manually to find the IDs for Boards, Sections, and Pins. The ID comes directly in the response data from the POST request for each of these actions, so I would like to request that it be included in the returned data from those functions. Right now, I believe they just return request response codes.

I will see if I can do it myself in the meantime, and I'll make a pull request if I get it working without any major changes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.