Skip to content
New issue

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

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

Already on GitHub? # to your account

Empty results from calls #484

Open
alexis2m opened this issue Jan 29, 2025 · 2 comments
Open

Empty results from calls #484

alexis2m opened this issue Jan 29, 2025 · 2 comments

Comments

@alexis2m
Copy link

alexis2m commented Jan 29, 2025

Whenever I try:

  • add_connection
  • get_profile_info
  • ...

I get an empty result; so an error without further explanations.

from fastapi import APIRouter, HTTPException, Depends, Body
from linkedin_api import Linkedin
from ..dependencies import rate_limiter, create_cookie_jar_from_browser_cookies
from ..models.requests import ProxyConfig, CookieConfig
from ..utils.logger import get_logger
from typing import Dict, List, Optional
from pydantic import BaseModel
import json
import os

router = APIRouter()
logger = get_logger(__name__)

class AuthConfig(BaseModel):
    cookies: List[Dict]  # Using Dict instead of CookieConfig to accept raw cookie data

class TestRequest(BaseModel):
    auth: Optional[AuthConfig] = None
    proxy: Optional[Dict] = None  # Using Dict to accept raw proxy data

class ProfileTestResponse(BaseModel):
    profile: Dict
    contact_info: Dict
    connections: List[Dict]

def create_test_linkedin_client(auth: Optional[AuthConfig] = None, proxy: Optional[Dict] = None) -> Linkedin:
    """Create a LinkedIn client using credentials or cookies"""
    try:    
        # Set up proxy if provided
        proxy_dict = None
        if proxy:
            proxy_url = f"http://{proxy['host']}:{proxy['port']}"
            if proxy.get('username') and proxy.get('password'):
                proxy_url = f"http://{proxy['username']}:{proxy['password']}@{proxy['host']}:{proxy['port']}"
            proxy_dict = {'https': proxy_url}
            logger.debug(f"Using proxy: {proxy_url}")
            
        # Create LinkedIn client
        if auth and auth.cookies:
            # Use cookie authentication
            cookie_jar = create_cookie_jar_from_browser_cookies(auth.cookies)
            logger.debug("Using cookie authentication")
            return Linkedin(
                 'privacy@mail.com',
                'myPassword',
                cookies=cookie_jar,
                proxies=proxy_dict,
                authenticate=True,
                refresh_cookies=True
            )
        else:
            # Use credentials authentication
            logger.debug("Using credentials authentication")
            return Linkedin(
                'privacy@mail.com',
                'myPassword',
                proxies=proxy_dict,
                authenticate=True,
                refresh_cookies=True
            )
        
    except Exception as e:
        logger.error(f"Failed to create LinkedIn client: {str(e)}")
        raise HTTPException(
            status_code=500,
            detail=f"Failed to create LinkedIn client: {str(e)}"
        )

@router.post("/test/{profile_id}", response_model=ProfileTestResponse)
async def test_profile_operations(
    profile_id: str,
    request: TestRequest,
    _: None = Depends(rate_limiter)
):
    """
    Test endpoint that performs multiple LinkedIn operations using credentials file:
    1. Gets profile information
    2. Gets contact information
    3. Gets profile connections
    """
    try:
        logger.info(f"Starting test operations for profile: {profile_id}")
        
        # Create LinkedIn client
        client = create_test_linkedin_client(request.auth, request.proxy)
        logger.info("Created LinkedIn client")
        
        # Get profile information
        logger.info("Getting profile information...")
        profile = client.get_profile(profile_id)
        logger.info(f"Got profile for: {profile.get('full_name', 'Unknown')}")
        
        # Get contact information
        logger.info("Getting contact information...")
        contact_info = client.get_profile_contact_info(profile_id)
        logger.info("Got contact information")
        
        # Get connections
        logger.info("Getting profile connections...")
        connections = client.get_profile_connections(profile.get('profile_id'))
        logger.info(f"Got {len(connections)} connections")
        
        return ProfileTestResponse(
            profile=profile,
            contact_info=contact_info,
            connections=connections
        )
        
    except Exception as e:
        logger.error(f"Test operations failed: {str(e)}")
        raise HTTPException(
            status_code=500,
            detail=f"Test operations failed: {str(e)}"
        )

And the full error is: Test operations failed: Expecting value: line 1 column 1 (char 0)

Have you encountered this issue before ?

@khuluqilkarim
Copy link

khuluqilkarim commented Jan 30, 2025

i got the same problem, did you find any solution ?

@alexis2m
Copy link
Author

Nothing for now

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants