I developed a GUI python using custom Tkinter for AutoBlogging articles on Wordpress, But when publishing like two articles it doesn't continue it gives me the following errors:
Traceback (most recent call last):
File "C:\Users\karim\anaconda3\lib\threading.py", line 1016, in _bootstrap_inner
self.run()
File "C:\Users\karim\anaconda3\lib\threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\karim\Downloads\ctk\examples\complex_example.py", line 321, in start_threading
image = client.call(UploadFile(image_data))
File "C:\Users\karim\anaconda3\lib\site-packages\wordpress_xmlrpc\base.py", line 37, in call
raw_result = server_method(*args)
File "C:\Users\karim\anaconda3\lib\xmlrpc\client.py", line 1122, in __call__
return self.__send(self.__name, args)
File "C:\Users\karim\anaconda3\lib\xmlrpc\client.py", line 1464, in __request
response = self.__transport.request(
File "C:\Users\karim\anaconda3\lib\xmlrpc\client.py", line 1166, in request
return self.single_request(host, handler, request_body, verbose)
File "C:\Users\karim\anaconda3\lib\xmlrpc\client.py", line 1178, in single_request
http_conn = self.send_request(host, handler, request_body, verbose)
File "C:\Users\karim\anaconda3\lib\xmlrpc\client.py", line 1291, in send_request
self.send_content(connection, request_body)
File "C:\Users\karim\anaconda3\lib\xmlrpc\client.py", line 1321, in send_content
connection.endheaders(request_body)
File "C:\Users\karim\anaconda3\lib\http\client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\karim\anaconda3\lib\http\client.py", line 1076, in _send_output
self.send(chunk)
File "C:\Users\karim\anaconda3\lib\http\client.py", line 998, in send
self.sock.sendall(data)
File "C:\Users\karim\anaconda3\lib\ssl.py", line 1237, in sendall
v = self.send(byte_view[count:])
File "C:\Users\karim\anaconda3\lib\ssl.py", line 1206, in send
return self._sslobj.write(data)
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:2396)
if self.entry1.get().lower() == "uploaded":
print("Let's go woohooo!... `\n")
# WordPress API endpoint and credentials
url = 'https://blablablabla.wordpress.com/xmlrpc.php'
username = '[email protected]'
password = 'upupupupup'
# Pexels API endpoint and authentication token
pexels_url = 'https://api.pexels.com/v1/search'
pexels_api_key = 'PEXELS_API_KEY
# Create a client instance for WordPress
client = Client(url, username, password)
# Input the title and content of the article
file_path = 'titles.txt'
with open(file_path, 'r') as file:
titles = file.read().split(',')
articles = []
for i, title in enumerate(titles):
content = App.generate_articles(title, "Academic", 1500)
#articles.append({'title': title.strip(), 'content': content.strip()})
#title = articles['title']
#content = articles['content']
self.toplevel_window.article_label2.configure(text="ARTICLE NUMBER : "+str(num_article))
kw_extractor = yake.KeywordExtractor(top=10, stopwords=None)
keywords = kw_extractor.extract_keywords(title)
i = 0
v_new = []
for kw, v in keywords:
v_new.append(v)
i += 1
image_title = kw
break
# Set up the request headers for Pexels API
headers = {
'Authorization': pexels_api_key
}
print(image_title)
# Send a GET request to Pexels API for image search
response = requests.get(pexels_url, headers=headers, params={'query': ''.join(image_title), 'per_page': 1}, verify=True)
# Parse the JSON response
data = response.json()
time.sleep(1)
# Extract the list of photos from the response
photos = data.get('photos', [])
# Check if any photos are found
if photos:
photo_url = photos[0]['src']['original']
image_path = image_path = f"{i+1}_{keywords[0]}_{keywords[1]}.jpg" # Customize the image file name as desired
# Send a GET request to download the image
image_response = requests.get(photo_url)
# Save the image to a file
with open(image_path, 'wb') as image_file:
image_file.write(image_response.content)
else:
print("No suitable image found.")
# Create a new WordPress post
post = WordPressPost()
post.title = title
post.content = content
# Set the desired categories for the post
categories = [image_title]
post.terms_names = {
'category': categories # Specify the desired categories
}
# Upload and attach the image to the post
if photos:
with open(image_path, 'rb') as img:
image_data = {
'name': image_path,
'type': 'image/jpeg',
'bits': img.read(),
}
image = client.call(UploadFile(image_data))
post.thumbnail = image['id']
post.post_status = 'publish' # Set post status to publish
# Publish the post
post_id = client.call(NewPost(post))
print(f"Post '{title}' created successfully with ID: {post_id}")
else:
pass
I tried to add Verify=True
in the requests but it doesn't work;
has anyone face this problem before? Please let me know if there is anything I can do because I've been facing this problem a long time. I didn't find any valid solution.