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

Maven, MitmProxy version 9: AttributeError: module 'mitmproxy.http' has no attribute 'HTTPResponse' #20

Closed
bp32891 opened this issue May 4, 2023 · 16 comments

Comments

@bp32891
Copy link

bp32891 commented May 4, 2023

Hello,

I recently started a Maven project using mitmproxy-java. Anytime I try to change the status code of an intercepted call, I get this error: AttributeError: module 'mitmproxy.http' has no attribute 'HTTPResponse'

`List messages = new ArrayList<>();

    MitmproxyJava proxy = new MitmproxyJava("/Library/Frameworks/Python.framework/Versions/3.10/bin/mitmdump", (InterceptedMessage m) -> {
        messages.add(m);
        m.getResponse().setBody("Hi from Test".getBytes(StandardCharsets.UTF_8));
        m.getResponse().getHeaders().add(new String[]{"myTestResponseHeader", "myTestResponseHeaderValue"});
        m.getResponse().setStatusCode(500);
        return m;
    });
    proxy.start();

    Unirest.setProxy(new HttpHost("localhost", 8080));
    HttpResponse<String> response = Unirest.get("http://appium.io").asString();

    driver.get("http://appium.io");

    System.out.println("RESPONSE");
    System.out.println(messages.get(0));

    TimeUnit.SECONDS.sleep(15);

    proxy.stop();

    assertThat(response.getBody()).isEqualTo("Hi from Test");

    final InterceptedMessage firstMessage = messages.get(0);

    assertThat(firstMessage.getRequest().getUrl()).startsWith("http://appium.io/");
    assertThat(firstMessage.getRequest().getHeaders()).containsOnlyOnce(new String[]{"myTestHeader", "myTestValue"});
    assertThat(firstMessage.getResponse().getHeaders()).containsOnlyOnce(new String[]{"myTestResponseHeader", "myTestResponseHeaderValue"});
    System.out.println(firstMessage.getResponse().getStatusCode());
    assertThat(firstMessage.getResponse().getStatusCode()).isEqualTo(500);`

I see that the newest version is 2.0.2 and I'm hoping it has the fix. But currently only 2.0.1 is available on Maven to insert into the POM file.

@t-o-n-y-p
Copy link

t-o-n-y-p commented May 5, 2023

Hello, same thing here. Could you devs please push the fix to maven central? Thanks.

@shlmvgett
Copy link

Hi
The same problem is actual for us, could u update version on mvn repo?

@bp32891
Copy link
Author

bp32891 commented May 8, 2023

I did find a work around until they make a push. I created my on jar file from this repo and added it to my pom. Then I had to add more libraries but it now works. I no longer get the error message.

@Jonahss
Copy link
Member

Jonahss commented May 8, 2023

Sorry about the delay. I'll see about updating in Maven.

@valeo28
Copy link

valeo28 commented May 11, 2023

Hi! Please uploade it to Maven Central.

@Jonahss
Copy link
Member

Jonahss commented May 12, 2023

Hi, I've been busy on my Wyldcard project, but thanks for poking me to update this. I'll see if I can do it on Monday.

@jlipps
Copy link
Member

jlipps commented May 12, 2023

that's such a cool project dude!

@re-jim
Copy link

re-jim commented May 16, 2023

@Jonahss poke again, please update this.

@Jonahss
Copy link
Member

Jonahss commented May 18, 2023

I'm finally working on it :D
My credentials to Maven Central are no longer valid. I'm talking to the active Appium team to get access.

Thanks for pinging me, sorry for the delay.

@t-o-n-y-p
Copy link

Hello, how is the progress on this?

@Jonahss
Copy link
Member

Jonahss commented Sep 21, 2023

Hello. I think I have everything I need now. Will work on this today and tomorrow. Thanks again for pinging.

@Jonahss
Copy link
Member

Jonahss commented Sep 21, 2023

@t-o-n-y-p @re-jim v2.0.2 published to central repository.
Can you verify the code works as intended?

@t-o-n-y-p
Copy link

Unfortunately, I no longer have access to the environment to check it, thanks for publishing though :)

@Jonahss
Copy link
Member

Jonahss commented Sep 27, 2023 via email

@halilcifteci
Copy link

Hi, after upgrading my project, there was no problem. thanks @Jonahss

@Jonahss
Copy link
Member

Jonahss commented Jan 18, 2024

Yay! Okay, can close with confidence :D

@Jonahss Jonahss closed this as completed Jan 18, 2024
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

8 participants